Class: SimpleStateMachine::StateMachineDefinition
Overview
Defines state machine transitions
Defined Under Namespace
Modules: Mountable
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Mountable
event, events
#begin_states, #end_states, #states
#google_chart_url, #to_graphviz_dot
#add_events
Instance Attribute Details
#decorator ⇒ Object
9
10
11
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 9
def decorator
@decorator ||= decorator_class.new(@subject)
end
|
#decorator_class ⇒ Object
13
14
15
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 13
def decorator_class
@decorator_class ||= Decorator::Default
end
|
#default_error_state ⇒ Object
17
18
19
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 17
def default_error_state
@default_error_state && @default_error_state.to_s
end
|
#state_method ⇒ Object
39
40
41
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 39
def state_method
@state_method ||= :state
end
|
#subject=(value) ⇒ Object
Sets the attribute subject
6
7
8
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 6
def subject=(value)
@subject = value
end
|
Instance Method Details
#add_transition(event_name, from, to) ⇒ Object
33
34
35
36
37
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 33
def add_transition event_name, from, to
transition = Transition.new(event_name, from, to)
transitions << transition
decorator.decorate(transition)
end
|
#define_event(event_name, state_transitions) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 25
def define_event event_name, state_transitions
state_transitions.each do |froms, to|
[froms].flatten.each do |from|
add_transition(event_name, from, to)
end
end
end
|
#to_s ⇒ Object
Human readable format: old_state.event! => new_state
44
45
46
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 44
def to_s
transitions.map(&:to_s).join("\n")
end
|
#transitions ⇒ Object
21
22
23
|
# File 'lib/simple_state_machine/state_machine_definition.rb', line 21
def transitions
@transitions ||= []
end
|