Class: Eco::API::Error::Handlers

Inherits:
UseCases show all
Defined in:
lib/eco/api/error/handlers.rb

Instance Method Summary collapse

Methods inherited from UseCases

#case, #defined?, #dup, #each, #empty?, #initialize, #items, #length, #merge, #name?, #names, #types

Methods included from Language::Klass::AutoLoader

#_autoload_namespace, #autoload_children!, #autoload_class?, #autoload_namespace, #autoload_namespace_ignore, #autoloaded_children, #autoloaded_class, #autoloaded_namespaces, #autoloads_children_of, #known_class!, #known_classes, #new_classes, #unloaded_children

Methods included from Language::Klass::Hierarchy

#descendants, #descendants?

Methods included from Language::Klass::Resolver

#class_resolver, #resolve_class

Constructor Details

This class inherits a constructor from Eco::API::UseCases

Instance Method Details

#add(handler) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
# File 'lib/eco/api/error/handlers.rb', line 27

def add(handler)
  msg = "Expected Eco::API::Error::Handler object. Given: #{handler.class}"
  raise ArgumentError, msg unless handler.is_a?(Eco::API::Error::Handler)

  super
end

#define(*_args) ⇒ Object



8
9
10
# File 'lib/eco/api/error/handlers.rb', line 8

def define(*_args)
  raise "Missusage. You should use 'on' method instead"
end

#on(klass_err, type: :error_handler, &block) ⇒ Object

Parameters:

  • klass_err (Eco::API::Error)

    the specific error class that triggers this handler.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/eco/api/error/handlers.rb', line 13

def on(klass_err, type: :error_handler, &block)
  Eco::API::Error.validate_err_class(klass_err)
  raise 'Expected block but not given' unless block

  Eco::API::Error::Handler.new(
    klass_err,
    type: type,
    root: self,
    &block
  ).tap do |handler|
    add(handler)
  end
end