Class: NxtStateMachine::Event
- Inherits:
-
Object
- Object
- NxtStateMachine::Event
- Includes:
- NxtRegistry
- Defined in:
- lib/nxt_state_machine/event.rb
Defined Under Namespace
Classes: Names
Instance Attribute Summary collapse
-
#event_transitions ⇒ Object
readonly
Returns the value of attribute event_transitions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#state_machine ⇒ Object
readonly
Returns the value of attribute state_machine.
Instance Method Summary collapse
-
#initialize(name, state_machine, **options, &block) ⇒ Event
constructor
A new instance of Event.
- #to_s ⇒ Object
- #transitions(from:, to:, &block) ⇒ Object (also: #transition)
- #transitions_from?(state) ⇒ Boolean
Constructor Details
#initialize(name, state_machine, **options, &block) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/nxt_state_machine/event.rb', line 5 def initialize(name, state_machine, **, &block) @state_machine = state_machine @name = name @event_transitions = registry("#{name} event transitions") @names = Event::Names.build(name) @options = .with_indifferent_access configure(&block) ensure_event_has_transitions end |
Instance Attribute Details
#event_transitions ⇒ Object (readonly)
Returns the value of attribute event_transitions.
17 18 19 |
# File 'lib/nxt_state_machine/event.rb', line 17 def event_transitions @event_transitions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/nxt_state_machine/event.rb', line 17 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
17 18 19 |
# File 'lib/nxt_state_machine/event.rb', line 17 def names @names end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/nxt_state_machine/event.rb', line 17 def @options end |
#state_machine ⇒ Object (readonly)
Returns the value of attribute state_machine.
17 18 19 |
# File 'lib/nxt_state_machine/event.rb', line 17 def state_machine @state_machine end |
Instance Method Details
#to_s ⇒ Object
45 46 47 |
# File 'lib/nxt_state_machine/event.rb', line 45 def to_s "#{self.class.name}[:#{name}]" end |
#transitions(from:, to:, &block) ⇒ Object Also known as: transition
31 32 33 34 35 36 37 |
# File 'lib/nxt_state_machine/event.rb', line 31 def transitions(from:, to:, &block) Array(from).each do |from_state| transition = Transition::Factory.new(name, from: from_state, to: to, state_machine: state_machine, &block) state_machine.transitions << transition event_transitions.register(from_state, transition) end end |
#transitions_from?(state) ⇒ Boolean
41 42 43 |
# File 'lib/nxt_state_machine/event.rb', line 41 def transitions_from?(state) event_transitions.resolve(state).present? end |