class NxtStateMachine::Event
Attributes
event_transitions[R]
name[R]
names[R]
options[R]
state_machine[R]
Public Class Methods
new(name, state_machine, **options, &block)
click to toggle source
# File lib/nxt_state_machine/event.rb, line 5 def initialize(name, state_machine, **options, &block) @state_machine = state_machine @name = name @event_transitions = registry("#{name} event transitions") @names = Event::Names.build(name) @options = options.with_indifferent_access configure(&block) ensure_event_has_transitions end
Public Instance Methods
to_s()
click to toggle source
# File lib/nxt_state_machine/event.rb, line 45 def to_s "#{self.class.name}[:#{name}]" end
transitions(from:, to:, &block)
click to toggle source
# 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
Also aliased as: transition
transitions_from?(state)
click to toggle source
# File lib/nxt_state_machine/event.rb, line 41 def transitions_from?(state) event_transitions.resolve(state).present? end
Private Instance Methods
configure(&block)
click to toggle source
# File lib/nxt_state_machine/event.rb, line 51 def configure(&block) instance_exec(&block) end
ensure_event_has_transitions()
click to toggle source
# File lib/nxt_state_machine/event.rb, line 55 def ensure_event_has_transitions return if event_transitions.size > 0 raise NxtStateMachine::Errors::EventWithoutTransitions, "No transitions for event :#{name} defined" end