Class: NxtStateMachine::ErrorCallbackRegistry

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

Instance Method Summary collapse

Instance Method Details

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



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

def register(from, to, error, 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).error(error, method_or_block)
    end
  end
end

#resolve(error, transition) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nxt_state_machine/error_callback_registry.rb', line 16

def resolve(error, transition)
  candidate = callbacks.from(
    transition.from.enum
  ).to(
    transition.to.enum
  ).error.keys.find { |kind_of_error| error.is_a?(kind_of_error) }

  return unless candidate

  callbacks.from(transition.from.enum).to(transition.to.enum).error(candidate)
end