Module: Compute

Defined in:
lib/compute.rb,
lib/compute/railtie.rb,
lib/compute/version.rb,
lib/compute/computation.rb,
lib/compute/computation_graph.rb

Defined Under Namespace

Modules: ClassMethods Classes: Computation, ComputationGraph, CyclicComputation, Railtie

Constant Summary collapse

VERSION =
"1.0.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
28
29
30
# File 'lib/compute.rb', line 25

def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    around_save :execute_outdated_computations
  end
end

Instance Method Details

#recompute!(*properties) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/compute.rb', line 32

def recompute!(*properties)
  properties = properties.compact.flatten
  if properties.empty?
    self.class.computations.each_in_order { |c| c.execute(self) }
  else
    properties.each do |property|
      computation = self.class.computations.for_property(property)
      computation.execute(self)
    end
  end
  save
end