Class: Granite::Represents::Attribute
- Inherits:
-
Form::Model::Attributes::Attribute
- Object
- Form::Model::Attributes::Attribute
- Granite::Represents::Attribute
- 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
- #changed? ⇒ Boolean
-
#initialize(*_args) ⇒ Attribute
constructor
A new instance of Attribute.
- #sync ⇒ Object
- #type_definition ⇒ Object
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
33 34 35 36 37 38 39 |
# File 'lib/granite/represents/attribute.rb', line 33 def changed? if reflection..key?(:default) reference.public_send(reader) != read else owner.public_send("#{name}_changed?") end end |
#sync ⇒ Object
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_definition ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/granite/represents/attribute.rb', line 25 def type_definition @type_definition ||= if reflection.[:type].present? build_type_definition(reflection.[:type]) else granite_form_type_definition || active_record_type_definition || super end end |