Class: AbstractMapper::Optimizer Private

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

Optimizes the immutable abstract syntax tree (AST) using comfigurable collection of applicable rules.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#rulesAbstractMapper::Rules (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 collection of applicable optimization rules.

Returns:



17
18
19
# File 'lib/abstract_mapper/optimizer.rb', line 17

def rules
  @rules
end

Class Method Details

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



29
30
31
32
# File 'lib/abstract_mapper/optimizer.rb', line 29

def initialize(rules)
  @rules = rules
  IceNine.deep_freeze(self)
end

.new(rules = Rules.new) ⇒ AbstractMapper::Optimizer

Creates the optimizer

Parameters:

  • rules (AbstractMapper::Rules) (defaults to: Rules.new)

    The collection of applicable optimization rules

Returns:



# File 'lib/abstract_mapper/optimizer.rb', line 19

.update(tree) ⇒ AbstractMapper::Branch

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.

Recursively optimizes the AST from root to leafs

Parameters:

  • tree (AbstractMapper::Branch)

Returns:

  • (AbstractMapper::Branch)


40
41
42
43
44
# File 'lib/abstract_mapper/optimizer.rb', line 40

def update(tree)
  return tree unless tree.is_a? AST::Branch
  new_tree = tree.update { rules[tree] }
  new_tree.update { new_tree.map(&method(:update)) }
end