Class: Serial::HashBuilder Private

Inherits:
Builder
  • Object
show all
Defined in:
lib/serial/hash_builder.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary

Attributes inherited from Builder

#data

Instance Method Summary collapse

Methods inherited from Builder

build, #build, #exec

Constructor Details

#initialize(context) {|_self| ... } ⇒ HashBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HashBuilder.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
# File 'lib/serial/hash_builder.rb', line 4

def initialize(context, &block)
  @context = context
  @data = {}
  yield self
end

Instance Method Details

#attribute(key, value = nil, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
# File 'lib/serial/hash_builder.rb', line 10

def attribute(key, value = nil, &block)
  value = build(HashBuilder, value, &block) if block
  @data[key.to_s] = value
end

#collection(key, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
# File 'lib/serial/hash_builder.rb', line 15

def collection(key, &block)
  list = build(ArrayBuilder, &block)
  attribute(key, list)
end

#map(key, list, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
# File 'lib/serial/hash_builder.rb', line 20

def map(key, list, &block)
  collection(key) do |builder|
    list.each do |item|
      builder.element { |element| element.exec(item, &block) }
    end
  end
end