Class: NxtStateMachine::Event

Inherits:
Object
  • Object
show all
Includes:
NxtRegistry
Defined in:
lib/nxt_state_machine/event.rb

Defined Under Namespace

Classes: Names

Instance Attribute Summary collapse

Instance Method Summary collapse

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, **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

Instance Attribute Details

#event_transitionsObject (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

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/nxt_state_machine/event.rb', line 17

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



17
18
19
# File 'lib/nxt_state_machine/event.rb', line 17

def names
  @names
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/nxt_state_machine/event.rb', line 17

def options
  @options
end

#state_machineObject (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_sObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/nxt_state_machine/event.rb', line 41

def transitions_from?(state)
  event_transitions.resolve(state).present?
end