Module: Veritas::Optimizer::Optimizable

Includes:
Immutable
Defined in:
lib/veritas/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/veritas/optimizer/optimizable.rb', line 18

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

Instance Method Details

#optimize(optimizer = self.class.optimizer || Optimizer::Noop) ⇒ Optimizable

TODO:

simplify by setting a default Noop optimizer for all relations

Optimize the operation

Examples:

optimized = operation.optimize

Parameters:

  • optimizer (Optimizer) (defaults to: self.class.optimizer || Optimizer::Noop)

    optional optimizer

Returns:



37
38
39
40
41
42
# File 'lib/veritas/optimizer/optimizable.rb', line 37

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