Class: Stateless::Engine
- Inherits:
-
Object
- Object
- Stateless::Engine
- Defined in:
- lib/stateless/engine.rb
Instance Attribute Summary collapse
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #can_transit_by_event?(from, event_name) ⇒ Boolean
- #can_transit_to_state?(from, to) ⇒ Boolean
-
#initialize(transitions) ⇒ Engine
constructor
A new instance of Engine.
- #transition_event(from, to) ⇒ Object
- #transition_state_by_event(from, event_name) ⇒ Object
Constructor Details
#initialize(transitions) ⇒ Engine
Returns a new instance of Engine.
5 6 7 |
# File 'lib/stateless/engine.rb', line 5 def initialize(transitions) @transitions = transitions end |
Instance Attribute Details
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
3 4 5 |
# File 'lib/stateless/engine.rb', line 3 def transitions @transitions end |
Instance Method Details
#can_transit_by_event?(from, event_name) ⇒ Boolean
18 19 20 |
# File 'lib/stateless/engine.rb', line 18 def can_transit_by_event?(from, event_name) transitions.any? { |transition| target_transition_by_event?(transition, from, event_name) } end |
#can_transit_to_state?(from, to) ⇒ Boolean
9 10 11 |
# File 'lib/stateless/engine.rb', line 9 def can_transit_to_state?(from, to) transitions.any? { |transition| target_transition_by_state?(transition, from, to) } end |
#transition_event(from, to) ⇒ Object
13 14 15 16 |
# File 'lib/stateless/engine.rb', line 13 def transition_event(from, to) transition = transitions.detect { |transition| target_transition_by_state?(transition, from, to) } transition&.event_name end |
#transition_state_by_event(from, event_name) ⇒ Object
22 23 24 25 |
# File 'lib/stateless/engine.rb', line 22 def transition_state_by_event(from, event_name) transition = transitions.detect { |transition| target_transition_by_event?(transition, from, event_name) } transition&.to end |