Class: AbstractMapper::Commands::Base Private

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

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



31
32
33
# File 'lib/abstract_mapper/commands/base.rb', line 31

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



25
26
27
# File 'lib/abstract_mapper/commands/base.rb', line 25

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



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

def name
  @name
end

Class Method Details

.call(*args, &block) ⇒ AbstractMapper::AST::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

  • block (Proc)

Returns:



60
61
62
63
# File 'lib/abstract_mapper/commands/base.rb', line 60

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.



44
45
46
47
48
49
50
# File 'lib/abstract_mapper/commands/base.rb', line 44

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

.new(name, klass, converter) ⇒ AbstractMapper::Commands::Base

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/commands/base.rb', line 33