Class: AbstractMapper::Rules Private

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_mapper/rules.rb,
lib/abstract_mapper/rules/base.rb,
lib/abstract_mapper/rules/pair.rb,
lib/abstract_mapper/rules/sole.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 rules applicable to nodes of AST

Defined Under Namespace

Classes: Base, Pair, Sole

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#registryArray<AbstractMapper::Rules::Base> (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 list of rules applicable to AST.

Returns:



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

def registry
  @registry
end

Class Method Details

.<<(other) ⇒ 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.

Returns the copy of current registry with the new rule added

Parameters:



43
44
45
# File 'lib/abstract_mapper/rules.rb', line 43

def <<(other)
  self.class.new(registry + [other])
end

.[](nodes) ⇒ Array<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.

Applies all the registered rules to the array of nodes

Parameters:

Returns:



53
54
55
# File 'lib/abstract_mapper/rules.rb', line 53

def [](nodes)
  @transproc ? @transproc[nodes] : nodes
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.



31
32
33
34
35
# File 'lib/abstract_mapper/rules.rb', line 31

def initialize(registry = [])
  @registry  = registry.dup
  @transproc = registry.map(&:transproc).inject(:>>)
  IceNine.deep_freeze(self)
end

.new(registry) ⇒ AbstractMapper::Rules

Creates a registry with array of rules

Parameters:

Returns:



# File 'lib/abstract_mapper/rules.rb', line 22