Class: NxtStateMachine::CallbackRegistry

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

Instance Method Summary collapse

Instance Method Details

#register(from, to, kind, method = nil, block = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/nxt_state_machine/callback_registry.rb', line 5

def register(from, to, kind, method = nil, block = nil)
  method_or_block = method || block
  return unless method_or_block

  Array(from).each do |from_state|
    Array(to).each do |to_state|
      callbacks.from!(from_state).to!(to_state).kind!(kind) << method_or_block
    end
  end
end

#resolve!(transition, kind = nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/nxt_state_machine/callback_registry.rb', line 16

def resolve!(transition, kind = nil)
  all_callbacks = callbacks.from!(transition.from.enum).to!(transition.to.enum)
  return all_callbacks unless kind

  all_callbacks.kind(kind)
end