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
-
.included(descendant) ⇒ self
private
Hook called when module is included.
Instance Method Summary collapse
-
#optimize(optimizer = self.class.optimizer || Optimizer::Noop) ⇒ Optimizable
Optimize the operation.
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
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
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 |