class FlowChart::Transition
Driver for Transition
in FlowChart
Attributes
branch[R]
condition[R]
from[R]
to[R]
Public Class Methods
new(options)
click to toggle source
# File lib/flowchart/flow_processor.rb, line 48 def initialize(options) @condition = options[:condition] @branch = options[:branch] @from = [options[:from]].flatten @to = options[:to] end
Public Instance Methods
get_me_next_state(base)
click to toggle source
# File lib/flowchart/flow_processor.rb, line 55 def get_me_next_state(base) raise InvalidTransition.new("You cannot transit from multiple states without a decision condition!") if @to.is_a?(Array) && @branch.nil? ## If to is a single state then just pass it on! if !@to.is_a?(Array) return @to end ## If to is an Array it means decision has to be made based on branching conditions to choose the to state! to = process_flow(@branch, base) ## If result to state coming from branching condition is not part of the set mentioned in to then next state transit is not possible! raise InvalidState.new("Your decision condition did not lead to transition state mentioned in :to clause!") unless @to.include?(to) to end
shall_i_trasit?(base)
click to toggle source
# File lib/flowchart/flow_processor.rb, line 68 def shall_i_trasit?(base) return true unless @condition ## If no condition has been given then transition is possible! ## If condition has been given then evaluate truth or falsity for transition to be possible! process_flow(@condition, base) end
Private Instance Methods
process_flow(action,base)
click to toggle source
# File lib/flowchart/flow_processor.rb, line 75 def process_flow(action,base) case action when Symbol, String base.send(action) when Proc action.call(base) end end