Class: Protoform::NamespaceCollection

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

Instance Attribute Summary

Attributes inherited from Node

#key, #parent

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of NamespaceCollection.



7
8
9
10
11
12
# File 'lib/protoform/namespace_collection.rb', line 7

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

Instance Method Details

#assign(array) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/protoform/namespace_collection.rb', line 18

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(&block) ⇒ Object



26
27
28
# File 'lib/protoform/namespace_collection.rb', line 26

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

#serializeObject



14
15
16
# File 'lib/protoform/namespace_collection.rb', line 14

def serialize
  map(&:serialize)
end