Class: Superform::FieldCollection
- Inherits:
-
Object
- Object
- Superform::FieldCollection
- Includes:
- Enumerable
- Defined in:
- lib/superform/field_collection.rb
Overview
A FieldCollection represents values that are collections of literals. For example, a Note ActiveRecord object might have a collection of tags that’s an array of string literals.
Instance Method Summary collapse
- #each ⇒ Object
- #field ⇒ Object
-
#initialize(field:) ⇒ FieldCollection
constructor
A new instance of FieldCollection.
- #values ⇒ Object
Constructor Details
#initialize(field:) ⇒ FieldCollection
Returns a new instance of FieldCollection.
7 8 9 10 11 |
# File 'lib/superform/field_collection.rb', line 7 def initialize(field:, &) @field = field @index = 0 each(&) if block_given? end |
Instance Method Details
#each ⇒ Object
13 14 15 16 17 |
# File 'lib/superform/field_collection.rb', line 13 def each(&) values.each do |value| yield build_field(value: value) end end |
#field ⇒ Object
19 20 21 |
# File 'lib/superform/field_collection.rb', line 19 def field build_field end |
#values ⇒ Object
23 24 25 |
# File 'lib/superform/field_collection.rb', line 23 def values Array(@field.value) end |