Class: Superform::NamespaceCollection
- Includes:
- Enumerable
- Defined in:
- lib/superform/namespace_collection.rb
Overview
A NamespaceCollection represents values that are collections of namespaces. For example, a User ActiveRecord object might have many Addresses. Each individual address is then delegated out to a Namespace object.
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Attributes inherited from Node
Instance Method Summary collapse
- #assign(array) ⇒ Object
- #each ⇒ Object
-
#initialize(key, parent:, form: parent.form, &template) ⇒ NamespaceCollection
constructor
A new instance of NamespaceCollection.
- #serialize ⇒ Object
Constructor Details
#initialize(key, parent:, form: parent.form, &template) ⇒ NamespaceCollection
Returns a new instance of NamespaceCollection.
10 11 12 13 14 15 |
# File 'lib/superform/namespace_collection.rb', line 10 def initialize(key, parent:, form: parent.form, &template) super(key, parent:) @template = template @form = form @namespaces = enumerate(parent_collection) end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
8 9 10 |
# File 'lib/superform/namespace_collection.rb', line 8 def form @form end |
Instance Method Details
#assign(array) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/superform/namespace_collection.rb', line 21 def assign(array) # The problem with zip-ing the array is if I need to add new # elements to it and wrap it in the namespace. zip(array) do |namespace, hash| namespace.assign hash end end |
#each ⇒ Object
29 30 31 |
# File 'lib/superform/namespace_collection.rb', line 29 def each(&) @namespaces.each(&) end |
#serialize ⇒ Object
17 18 19 |
# File 'lib/superform/namespace_collection.rb', line 17 def serialize map(&:serialize) end |