Class: AbstractMapper::Command Private

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_mapper/command.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.

Describes the command of the mapper

Every command has a name, a node that is added to the AST and the function, that converts command attributes into the node’s.

Method ‘#call` builds a correspodning node for the AST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#converter#call (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 converter of the command’s arguments into the node’s.

Returns:

  • (#call)

    The converter of the command’s arguments into the node’s



32
33
34
# File 'lib/abstract_mapper/command.rb', line 32

def converter
  @converter
end

#klassClass (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 class of the node to be created.

Returns:

  • (Class)

    The class of the node to be created



26
27
28
# File 'lib/abstract_mapper/command.rb', line 26

def klass
  @klass
end

#nameSymbol (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 name of the DSL command.

Returns:

  • (Symbol)

    The name of the DSL command



20
21
22
# File 'lib/abstract_mapper/command.rb', line 20

def name
  @name
end

Class Method Details

.call(*args, &block) ⇒ AbstractMapper::Node

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 the AST node

Parameters:

  • args (Object, Array)

    The argument of the command that should be converted to node attributes

  • block (Proc)

Returns:



61
62
63
64
# File 'lib/abstract_mapper/command.rb', line 61

def call(*args, &block)
  block = nil if @branch
  klass.new(converter.call(*args), &block)
end

.initialize(name, klass, converter = nil) ⇒ 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.



45
46
47
48
49
50
51
# File 'lib/abstract_mapper/command.rb', line 45

def initialize(name, klass, converter = nil)
  @name = name.to_sym
  @klass = klass
  @branch = Functions[:subclass?, Branch][klass]
  @converter = converter || proc { |args = {}| args }
  IceNine.deep_freeze(self)
end

.new(name, klass, converter) ⇒ AbstractMapper::Command

Creates the named command for node klass and arguments converter

Parameters:

  • name (#to_sym)

    The name of the DSL command

  • klass (Class)

    The klass of the node to be created

  • converter (#call)

    The function that coerces attributes

Returns:



# File 'lib/abstract_mapper/command.rb', line 34