Class: TrafficLight
- Inherits:
-
Object
- Object
- TrafficLight
- Defined in:
- traffic_light.rb
State Machines
This class contains 1 state machine(s).state

Instance Attribute Summary (collapse)
-
- (Object) state
Gets the current attribute value for the machine.
Class Method Summary (collapse)
-
+ (String) human_state_event_name(event)
Gets the humanized name for the given event.
-
+ (String) human_state_name(state)
Gets the humanized name for the given state.
Instance Method Summary (collapse)
-
- (Boolean) can_cycle?(requirements = {})
Checks whether :cycle can be fired.
-
- (Boolean) caution?
Checks whether :caution is the current state.
-
- (Boolean) cycle(*args)
Fires the :cycle event.
-
- (Boolean) cycle!(*args)
Fires the :cycle event, raising an exception if it fails.
-
- (StateMachine::Transition) cycle_transition(requirements = {})
Gets the next transition that would be performed if :cycle were to be fired.
-
- (Boolean) fire_state_event(event, *args)
Fires an arbitrary state event with the given argument list.
-
- (String) human_state_name
Gets the human-readable name of the state for the current value.
-
- (Boolean) proceed?
Checks whether :proceed is the current state.
-
- (Boolean) state?(state_name)
Checks the given state name against the current state.
-
- (Array<Symbol>) state_events(requirements = {})
Gets the list of events that can be fired on the current state (uses the unqualified event names).
-
- (Symbol) state_name
Gets the internal name of the state for the current value.
-
- (StateMachine::PathCollection) state_paths(requirements = {})
Gets the list of sequences of transitions that can be run for the current state.
-
- (Array<StateMachine::Transition>) state_transitions(requirements = {})
Gets the list of transitions that can be made for the current state.
-
- (Boolean) stop?
Checks whether :stop is the current state.
Instance Attribute Details
- (Object) state
Gets the current attribute value for the machine
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
Class Method Details
+ (String) human_state_event_name(event)
Gets the humanized name for the given event.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
+ (String) human_state_name(state)
Gets the humanized name for the given state.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
Instance Method Details
- (Boolean) can_cycle?(requirements = {})
Checks whether :cycle can be fired.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) caution?
Checks whether :caution is the current state.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) cycle(*args)
Fires the :cycle event.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) cycle!(*args)
Fires the :cycle event, raising an exception if it fails.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (StateMachine::Transition) cycle_transition(requirements = {})
Gets the next transition that would be performed if :cycle were to be fired.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) fire_state_event(event, *args)
Fires an arbitrary state event with the given argument list
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (String) human_state_name
Gets the human-readable name of the state for the current value.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) proceed?
Checks whether :proceed is the current state.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) state?(state_name)
Checks the given state name against the current state.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Array<Symbol>) state_events(requirements = {})
Gets the list of events that can be fired on the current state (uses the unqualified event names)
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Symbol) state_name
Gets the internal name of the state for the current value.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (StateMachine::PathCollection) state_paths(requirements = {})
Gets the list of sequences of transitions that can be run for the current state
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Array<StateMachine::Transition>) state_transitions(requirements = {})
Gets the list of transitions that can be made for the current state
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |
- (Boolean) stop?
Checks whether :stop is the current state.
4 5 6 7 8 |
# File 'traffic_light.rb', line 4 state_machine :initial => :stop do event :cycle do transition :stop => :proceed, :proceed => :caution, :caution => :stop end end |