class AbstractMapper::Builder

Builds the immutable abstract syntax tree (AST) using DSL commands.

@example

Builder.update do
  field :user do     # DSL method
    add_prefix :user # DSL method for subtree
  end
end
# => <Root() [<Field(:user) [<AddPrefix(:user)>]>]>

@api private

Attributes

commands[W]

@!attribute [rw] commands

@return [AbstractMapper::Commands] The registry of DSL commands

tree[R]

@!attribute [r] tree

@return [AbstractMapper::Branch] The updated tree

Public Class Methods

commands() click to toggle source
# File lib/abstract_mapper/builder.rb, line 27
def commands
  @commands ||= AbstractMapper::Commands
end
new(node, &block) click to toggle source

@private

# File lib/abstract_mapper/builder.rb, line 64
def initialize(node, &block)
  @tree     = node
  @commands = self.class.commands
  instance_eval(&block) if block_given?
  IceNine.deep_freeze(self)
end
update(node = AST::Branch.new, &block) click to toggle source

Updates given node by adding its subnode from the block

@param [AbstractMapper::Branch] node

The root of the tree to be updated

@param [Proc] block

The block with DSL commands for adding subnodes

@return (see tree)

# File lib/abstract_mapper/builder.rb, line 42
def self.update(node = AST::Branch.new, &block)
  new(node, &block).tree
end