Class: Granite::Form::Model::Attributes::Represents

Inherits:
Attribute
  • Object
show all
Defined in:
lib/granite/form/model/attributes/represents.rb

Instance Attribute Summary

Attributes inherited from Base

#type_definition

Instance Method Summary collapse

Methods inherited from Attribute

#default, #defaultize, #normalize, #read, #read_before_type_cast, #write

Methods inherited from Base

#came_from_default?, #came_from_user?, #inspect_attribute, #pollute, #query, #read, #read_before_type_cast, #readonly?, #reset, #value_present?, #write, #write_value

Constructor Details

#initialize(*_args) ⇒ Represents

Returns a new instance of Represents.



8
9
10
11
12
13
# File 'lib/granite/form/model/attributes/represents.rb', line 8

def initialize(*_args)
  super

  set_default_value
  set_default_value_before_type_cast
end

Instance Method Details

#changed?Boolean

Returns:



19
20
21
22
23
24
25
# File 'lib/granite/form/model/attributes/represents.rb', line 19

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

#syncObject



15
16
17
# File 'lib/granite/form/model/attributes/represents.rb', line 15

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