Class: AbstractMapper::Commands Private

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_mapper/commands.rb

Overview

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.

Registry of DSL commands used by the builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#registryHash<Symbol => Class> (readonly)

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 The registry of command names, pointing to types of the nodes, that should be built for adding to AST.

Returns:

  • (Hash<Symbol => Class>)

    The registry of command names, pointing to types of the nodes, that should be built for adding to AST



17
18
19
# File 'lib/abstract_mapper/commands.rb', line 17

def registry
  @registry
end

Class Method Details

.<<(other) ⇒ undefined

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 immutable registry with added command name and type

Parameters:

  • other (Array<Symbol, Class>)

Returns:

  • (undefined)


39
40
41
42
43
# File 'lib/abstract_mapper/commands.rb', line 39

def <<(other)
  name = other[0]
  node = other[1]
  self.class.new registry.merge(name.to_sym => node)
end

.[](name, *args, &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.

Builds a node by the name of DSL command

Skips the block if a registered node is a branch

Parameters:

  • name (#to_sym)

    The name of the command

  • args (Object, Array)

    The command’s arguments

  • block (Proc)

    The block to be passed to the constructor of the simple node

Raises:



57
58
59
60
61
# File 'lib/abstract_mapper/commands.rb', line 57

def [](name, *args, &block)
  type   = get(name)
  branch = Functions[:subclass?, Branch][type]
  branch ? type.new(*args) : type.new(*args, &block)
end

.initialize(registry = {}) ⇒ 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.



28
29
30
31
# File 'lib/abstract_mapper/commands.rb', line 28

def initialize(registry = {})
  @registry = registry.dup.freeze
  freeze
end

.new(registry = {}) ⇒ Faceter::Commands

Creates an immutable collection of commands

Parameters:

  • registry (Hash) (defaults to: {})

Returns:

  • (Faceter::Commands)


# File 'lib/abstract_mapper/commands.rb', line 19