Class: Superform::FieldCollection

Inherits:
Object
  • Object
show all
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

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

#eachObject



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

#fieldObject



19
20
21
# File 'lib/superform/field_collection.rb', line 19

def field
  build_field
end

#valuesObject



23
24
25
# File 'lib/superform/field_collection.rb', line 23

def values
  Array(@field.value)
end