Class: Superform::NamespaceCollection

Inherits:
Node
  • Object
show all
Includes:
Enumerable
Defined in:
lib/superform.rb

Instance Attribute Summary

Attributes inherited from Node

#key, #parent

Instance Method Summary collapse

Constructor Details

#initialize(key, parent:, &template) ⇒ NamespaceCollection

Returns a new instance of NamespaceCollection.



264
265
266
267
268
# File 'lib/superform.rb', line 264

def initialize(key, parent:, &template)
  super(key, parent: parent)
  @template = template
  @namespaces = enumerate(parent_collection)
end

Instance Method Details

#assign(array) ⇒ Object



274
275
276
277
278
279
280
# File 'lib/superform.rb', line 274

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

#eachObject



282
283
284
# File 'lib/superform.rb', line 282

def each(&)
  @namespaces.each(&)
end

#serializeObject



270
271
272
# File 'lib/superform.rb', line 270

def serialize
  map(&:serialize)
end