Class: AbstractMapper::Rules::Base Abstract Private

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

This class is abstract.

Base class for optimization rules

API:

  • private

Direct Known Subclasses

Pair, Sole

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*nodes) ⇒ AbstractMapper::Rules::Base

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.

Initializes the rule for a sole node, or a pair of consecutive nodes

Parameters:

API:

  • private



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

def initialize(*nodes)
  @nodes = nodes
  IceNine.deep_freeze(self)
end

Instance Attribute Details

#nodesArray<AbstractMapper::AST::Node> (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 Either one or two nodes to be optimized.

Returns:

  • Either one or two nodes to be optimized

API:

  • private



34
35
36
# File 'lib/abstract_mapper/rules/base.rb', line 34

def nodes
  @nodes
end

Class Method Details

.transprocTransproc::Function

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.

The transformation function that applies the rule to the array of nodes

Returns:

API:

  • private



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

def self.transproc
  Functions[composer, proc { |*nodes| new(*nodes).call }]
end

Instance Method Details

#callArray<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.

Returns the result of the rule applied to the initialized [#nodes]

Returns:

API:

  • private



66
67
68
# File 'lib/abstract_mapper/rules/base.rb', line 66

def call
  optimize? ? [optimize].flatten.compact : nodes
end

#optimizeObject

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 optimized node(s)

Returns:

API:

  • private



58
59
60
# File 'lib/abstract_mapper/rules/base.rb', line 58

def optimize
  nodes
end

#optimize?Boolean

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.

Checks if optimization is needed for the node(s)

Returns:

API:

  • private



51
52
# File 'lib/abstract_mapper/rules/base.rb', line 51

def optimize?
end