class NxtStateMachine::ErrorCallbackRegistry

Public Instance Methods

register(from, to, error, method = nil, block = nil) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

callbacks() click to toggle source
# File lib/nxt_state_machine/error_callback_registry.rb, line 30
def callbacks
  @callbacks ||= registry :from do
    level :to do
      level :error, transform_keys: false, call: false
    end
  end
end