Class: Protoform::Field
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dom ⇒ Object
readonly
Returns the value of attribute dom.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Attributes inherited from Node
Instance Method Summary collapse
- #assign(value) ⇒ Object (also: #value=)
-
#collection(&block) ⇒ Object
Wraps a field that’s an array of values with a bunch of fields that are indexed with the array’s index.
-
#initialize(key, parent:, object: nil, value: nil) ⇒ Field
constructor
A new instance of Field.
- #value ⇒ Object (also: #serialize)
Constructor Details
Instance Attribute Details
#dom ⇒ Object (readonly)
Returns the value of attribute dom.
5 6 7 |
# File 'lib/protoform/field.rb', line 5 def dom @dom end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/protoform/field.rb', line 5 def object @object end |
Instance Method Details
#assign(value) ⇒ Object Also known as: value=
23 24 25 26 27 28 29 |
# File 'lib/protoform/field.rb', line 23 def assign(value) if @object.respond_to? :"#{@key}=" @object.send :"#{@key}=", value else @value = value end end |
#collection(&block) ⇒ Object
Wraps a field that’s an array of values with a bunch of fields that are indexed with the array’s index.
34 35 36 |
# File 'lib/protoform/field.rb', line 34 def collection(&block) @collection ||= FieldCollection.new(field: self, &block) end |
#value ⇒ Object Also known as: serialize
14 15 16 17 18 19 20 |
# File 'lib/protoform/field.rb', line 14 def value if @object.respond_to? @key.to_s @object.send @key else @value end end |