Class: Wait::BaseRescuer

Inherits:
Object
  • Object
show all
Defined in:
lib/rescuers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exceptions) ⇒ BaseRescuer

Returns a new instance of BaseRescuer.



6
7
8
# File 'lib/rescuers/base.rb', line 6

def initialize(exceptions)
  @exceptions = Array(exceptions).flatten
end

Instance Attribute Details

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



4
5
6
# File 'lib/rescuers/base.rb', line 4

def exceptions
  @exceptions
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/rescuers/base.rb', line 3

def logger
  @logger
end

Instance Method Details

#indent(lines, spaces = 25) ⇒ Object

Indents text a given number of spaces.



24
25
26
# File 'lib/rescuers/base.rb', line 24

def indent(lines, spaces = 25)
  lines.map { |line| (" " * spaces) + line }.join("\n")
end

#log(exception) ⇒ Object

Logs an exception.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rescuers/base.rb', line 11

def log(exception)
  return if @logger.nil?

  klass = exception.class.name
  # We can omit the message if it's identical to the class name.
  message = exception.message unless exception.message == klass
  # Indent the exception so it stands apart from the rest of the messages.
  backtrace = indent(exception.backtrace)

  @logger.debug("Rescuer") { "rescued: #{klass}#{": #{message}" if message}\n#{backtrace}" }
end