Class: Limiter::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/limiter/error_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



10
11
12
# File 'lib/limiter/error_handler.rb', line 10

def initialize(error)
  @error = error
end

Class Method Details

.error(error) ⇒ Object



6
7
8
# File 'lib/limiter/error_handler.rb', line 6

def self.error(error)
  new(error).handle_error
end

Instance Method Details

#handle_errorObject



14
15
16
17
18
19
20
# File 'lib/limiter/error_handler.rb', line 14

def handle_error
  if !production?
    raise Error, @error
  else
    log @error
  end
end

#log(error) ⇒ Object



30
31
32
33
# File 'lib/limiter/error_handler.rb', line 30

def log(error)
  @logger ||= Logger.new(STDOUT)
  @logger.error(error)
end

#production?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/limiter/error_handler.rb', line 22

def production?
  if defined?(Rails)
    Rails.env.production?
  else
    (ENV["RACK_ENV"] || ENV["RAILS_ENV"] ) == "production"
  end
end