class Laminar::Flow::Step
Specification
for an executable step in a Flow
.
Attributes
branches[R]
class_name[R]
name[R]
Public Class Methods
new(name, options = {}, &block)
click to toggle source
# File lib/laminar/flow/step.rb, line 16 def initialize(name, options = {}, &block) raise ArgumentError, 'invalid name' unless name.class.method_defined?(:to_sym) validate_options(options) @class_name = (options[:class] || name).to_s.camelize @name = name.to_sym @branches = [] instance_eval(&block) if block end
Public Instance Methods
after(*args, &block)
click to toggle source
Defines a callback to run after the flow executes the step.
# File lib/laminar/flow/step.rb, line 65 def after(*args, &block) after_callbacks.concat(args) after_callbacks << block if block end
after_callbacks()
click to toggle source
Return the list of after callbacks.
# File lib/laminar/flow/step.rb, line 76 def after_callbacks @after_callbacks ||= [] end
before(*args, &block)
click to toggle source
Defines a callback to run before the flow executes the step.
# File lib/laminar/flow/step.rb, line 59 def before(*args, &block) before_callbacks.concat(args) before_callbacks << block if block end
before_callbacks()
click to toggle source
Return the list of before callbacks.
# File lib/laminar/flow/step.rb, line 71 def before_callbacks @before_callbacks ||= [] end
branch(target, options = {})
click to toggle source
Add a branch specification. This is typically called as part of a flow specification:
flow do
step :step1
end
# File lib/laminar/flow/step.rb, line 39 def branch(target, options = {}) branches << Branch.new(target, options) end
Also aliased as: goto
endflow(options = {})
click to toggle source
# File lib/laminar/flow/step.rb, line 44 def endflow(options = {}) branches << Branch.new(:endflow, options) end
first_applicable_branch(target)
click to toggle source
Return the first branch that satisfies its condition.
# File lib/laminar/flow/step.rb, line 81 def first_applicable_branch(target) branches.each do |branch| return branch if branch.meets_condition?(target) end nil end
next_step_name(impl_context)
click to toggle source
Find the next rule in the flow. Examines the branches associated with the current rule and returns the name of the first branch that satisfies its condition.
# File lib/laminar/flow/step.rb, line 51 def next_step_name(impl_context) branch = first_applicable_branch(impl_context) return if branch.nil? branch.name end
particle()
click to toggle source
Return class instance of the associated particle.
# File lib/laminar/flow/step.rb, line 28 def particle class_name.constantize end