Class: Orchestrated::OrchestrationDependency
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Orchestrated::OrchestrationDependency
- Defined in:
- lib/orchestrated/dependency.rb
Instance Method Summary collapse
- #_constrain ⇒ Object
- #call_dependent {|dependent| ... } ⇒ Object
- #constrain ⇒ Object
- #save_avoiding_recursion ⇒ Object
Instance Method Details
#_constrain ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/orchestrated/dependency.rb', line 35 def _constrain if prerequisite.present? # This method can be called more than once in general since it is called # as part of validation. Rather than loosening the state machine (to allow # e.g. complete=>complete) we explicitly avoid re-submitting events here. prerequisite_completed if prerequisite.complete? && can_prerequisite_completed? prerequisite_canceled if prerequisite.canceled? && can_prerequisite_canceled? end true end |
#call_dependent {|dependent| ... } ⇒ Object
28 29 30 |
# File 'lib/orchestrated/dependency.rb', line 28 def call_dependent(&block) yield dependent unless dependent.nil? end |
#constrain ⇒ Object
31 32 33 34 |
# File 'lib/orchestrated/dependency.rb', line 31 def constrain @saving = true _constrain.tap{@saving = false} end |
#save_avoiding_recursion ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/orchestrated/dependency.rb', line 45 def save_avoiding_recursion # Default action of state_machine is "save", however that is # a problem when we need to transition state during validation # (see constrain method above). If were are validating then we # dursnt call save again. if @saving true # allow state transition but don't save ActiveRecord else save # save ActiveRecord as usual and return true/false end end |