class Stateful::States
Attributes
all[R]
Public Class Methods
new(klass, options = {})
click to toggle source
# File lib/Stateful/States.rb, line 11 def initialize(klass, options = {}) @klass = klass @options = options @all = [] @initial_state = nil @final_states = [] end
Public Instance Methods
detect(candidate_state)
click to toggle source
# File lib/Stateful/States.rb, line 19 def detect(candidate_state) candidate_state_name = ( if candidate_state.is_a?(State) candidate_state.name else candidate_state && candidate_state.to_sym end ) self.all.detect{|state| state.name == candidate_state_name} end
Also aliased as: find
final_state(*state_names)
click to toggle source
# File lib/Stateful/States.rb, line 56 def final_state(*state_names) final_states(*state_names).first end
Also aliased as: final_state=
final_states(*state_names)
click to toggle source
# File lib/Stateful/States.rb, line 61 def final_states(*state_names) state_names = state_names.flatten if !state_names.empty? state_names.each do |state_name| final_state = State.new(state_name) @final_states << final_state all << final_state end @final_states else @final_states end end
find_or_create(state_name, options = {})
click to toggle source
# File lib/Stateful/States.rb, line 40 def find_or_create(state_name, options = {}) find(state_name) || ( state = State.new(state_name, options) all << state state ) end
initial_state(state_name = nil, options = {}, &block)
click to toggle source
# File lib/Stateful/States.rb, line 48 def initial_state(state_name = nil, options = {}, &block) if state_name @initial_state = state(state_name, options, &block) else @initial_state end end
missing?(state)
click to toggle source
# File lib/Stateful/States.rb, line 31 def missing?(state) !detect(state) end
Also aliased as: new_state?
present?(state)
click to toggle source
# File lib/Stateful/States.rb, line 36 def present?(state) !!detect(state) end
state(state_name, options = {}, &block)
click to toggle source
# File lib/Stateful/States.rb, line 75 def state(state_name, options = {}, &block) options.merge!(non_deterministic_event_ordering: global_non_deterministic_event_ordering?) state = find_or_create(state_name, options) state.instance_eval(&block) if block state.transitions.each do |transition| @klass.define_event_method(transition) end @klass.define_status_predicate_method(state_name) state end
stateful(options = {}, &block)
click to toggle source
# File lib/Stateful/States.rb, line 86 def stateful(options = {}, &block) @options = options instance_eval(&block) if block end
Private Instance Methods
global_non_deterministic_event_ordering?()
click to toggle source
# File lib/Stateful/States.rb, line 93 def global_non_deterministic_event_ordering? @options[:global_non_deterministic_event_ordering] || @options[:non_deterministic_event_ordering] || @options[:non_deterministic] || (@options[:deterministic] && !@options[:deterministic]) end