class AbstractMapper::Rules

Registry of DSL rules applicable to nodes of AST

@api private

Attributes

registry[R]

@!attribute [r] registry

@return [Array<AbstractMapper::Rules::Base>]

the list of rules applicable to AST

Public Class Methods

new(registry = []) click to toggle source

@private

# File lib/abstract_mapper/rules.rb, line 31
def initialize(registry = [])
  @registry  = registry.dup
  @transproc = registry.map(&:transproc).inject(:>>)
  IceNine.deep_freeze(self)
end

Public Instance Methods

<<(other) click to toggle source

Returns the copy of current registry with the new rule added

@param [AbstractMapper::Rules::Base] other

@return (see new)

# File lib/abstract_mapper/rules.rb, line 43
def <<(other)
  self.class.new(registry + [other])
end
[](nodes) click to toggle source

Applies all the registered rules to the array of nodes

@param [Array<AbstractMapper::AST::Node>] nodes

@return [Array<AbstractMapper::AST::Node>] The optimized array of nodes

# File lib/abstract_mapper/rules.rb, line 53
def [](nodes)
  @transproc ? @transproc[nodes] : nodes
end