Module: Axiom::Optimizer::Optimizable

Includes:
Adamantium
Defined in:
lib/axiom/optimizer/optimizable.rb

Overview

Allow operations to be optimizable

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(descendant) ⇒ self

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.

Hook called when module is included

Parameters:

  • descendant (Module)

    the module or class including Optimizable

Returns:

  • (self)


18
19
20
21
# File 'lib/axiom/optimizer/optimizable.rb', line 18

def self.included(descendant)
  descendant.extend ClassMethods
  self
end

Instance Method Details

#optimizeOptimizable

TODO:

simplify by setting a default Identity optimizer for all relations

Optimize the operation

Examples:

optimized = operation.optimize

Returns:



34
35
36
37
38
39
40
# File 'lib/axiom/optimizer/optimizable.rb', line 34

def optimize
  optimizer = self.class.optimizer || Optimizer::Identity
  optimized = optimizer.call(self)
  equal?(optimized)                ? self               :
  optimized.respond_to?(:optimize) ? optimized.optimize :
                                     optimized
end