module Laminar::Flow::InstanceMethods
Add instance methods and attributes
Public Instance Methods
call(*)
click to toggle source
Initiates evaluation of the flow. @param object the context/input on which the flow will operate.
# File lib/laminar/flow.rb, line 107 def call(*) return context if flowspec.nil? validate_required_context step = flowspec.steps[flowspec.first_step] loop do break unless invoke_step(step) step = next_step(step) end context end
flowspec()
click to toggle source
@return [FlowSpec] the flow specification for the class.
# File lib/laminar/flow.rb, line 101 def flowspec self.class.flowspec end
Private Instance Methods
guarded_callback(list)
click to toggle source
# File lib/laminar/flow.rb, line 148 def guarded_callback(list) return if context.halted? run_callbacks(list) end
invoke_step(step)
click to toggle source
# File lib/laminar/flow.rb, line 122 def invoke_step(step) return if step.nil? context[:__flow_step__] = step.name pre_step_callbacks(step) run_particle(step) post_step_callbacks(step) !context.halted? end
next_step(current)
click to toggle source
Given a step, returns the next step that satisfies the execution/branch conditions.
# File lib/laminar/flow.rb, line 156 def next_step(current) next_name = current.next_step_name(self) return nil unless next_name && next_name != :endflow unless flowspec.steps.key?(next_name) raise FlowError, "No rule with name or alias of #{next_name}" end flowspec.steps[next_name] end
post_step_callbacks(step)
click to toggle source
# File lib/laminar/flow.rb, line 132 def post_step_callbacks(step) guarded_callback(step.after_callbacks) guarded_callback(flowspec.after_each_callbacks) end
pre_step_callbacks(step)
click to toggle source
# File lib/laminar/flow.rb, line 137 def pre_step_callbacks(step) guarded_callback(flowspec.before_each_callbacks) guarded_callback(step.before_callbacks) end
run_particle(step)
click to toggle source
# File lib/laminar/flow.rb, line 142 def run_particle(step) return if context.halted? step.particle.call!(context) end
validate_required_context()
click to toggle source
# File lib/laminar/flow.rb, line 166 def validate_required_context missing = [] flowspec.flow_params.each do |param| next if context.key?(param) missing << param end return if missing.empty? raise ArgumentError, "missing context: #{missing.join(', ')}" end