Class: Granite::Represents::Attribute

Inherits:
Form::Model::Attributes::Attribute
  • Object
show all
Defined in:
lib/granite/represents/attribute.rb

Constant Summary collapse

TYPES =
types.freeze
GRANITE_COLLECTION_TYPES =
[
  Granite::Form::Model::Attributes::ReferenceMany,
  Granite::Form::Model::Attributes::Collection,
  Granite::Form::Model::Attributes::Dictionary
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Attribute

Returns a new instance of Attribute.



14
15
16
17
18
19
# File 'lib/granite/represents/attribute.rb', line 14

def initialize(*_args)
  super

  set_default_value
  set_default_value_before_type_cast
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/granite/represents/attribute.rb', line 33

def changed?
  if reflection.options.key?(:default)
    reference.public_send(reader) != read
  else
    owner.public_send("#{name}_changed?")
  end
end

#syncObject



21
22
23
# File 'lib/granite/represents/attribute.rb', line 21

def sync
  reference.public_send(writer, read) if reference.respond_to?(writer)
end

#type_definitionObject



25
26
27
28
29
30
31
# File 'lib/granite/represents/attribute.rb', line 25

def type_definition
  @type_definition ||= if reflection.options[:type].present?
                         build_type_definition(reflection.options[:type])
                       else
                         granite_form_type_definition || active_record_type_definition || super
                       end
end