Class: Serial::ArrayBuilder

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

Overview

A builder for building arrays. You most likely just want to look at the public API methods in this class.

Instance Attribute Summary

Attributes inherited from Builder

#data

Instance Method Summary collapse

Methods inherited from Builder

build, #exec

Constructor Details

#initialize(context) ⇒ ArrayBuilder

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 ArrayBuilder.



6
7
8
9
# File 'lib/serial/array_builder.rb', line 6

def initialize(context)
  @context = context
  @data = []
end

Instance Method Details

#collection {|builder| ... } ⇒ Object

Serializes a collection in a collection.

Examples:

h.collection() do |l|
  l.collection do |l|
    l.element {  }
  end
end

Yields:

  • (builder)

Yield Parameters:



39
40
41
# File 'lib/serial/array_builder.rb', line 39

def collection(&block)
  @data << ArrayBuilder.build(@context, &block)
end

#element {|builder| ... } ⇒ Object

Serializes a hash item in a collection.

Examples:

h.collection() do |l|
  l.element do |h|
    h.attribute()
  end
end

Yields:

  • (builder)

Yield Parameters:



23
24
25
# File 'lib/serial/array_builder.rb', line 23

def element(&block)
  @data << HashBuilder.build(@context, &block)
end