Class: ExceptionNotifier::YamlNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier/yaml_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ YamlNotifier

Returns a new instance of YamlNotifier.



6
7
8
9
# File 'lib/exception_notifier/yaml_notifier.rb', line 6

def initialize(options)
  # initialize options here
  @extra_params = options[:extra_params] || []
end

Instance Method Details

#call(exception, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/exception_notifier/yaml_notifier.rb', line 11

def call(exception, options={})
  log = ::YamlNotifier::ExceptionLog.new({
    title: exception.inspect,
    message: exception.message,
    backtrace: exception.backtrace.join("\n")
  })

  env = options[:env]
  unless env.nil?
    log.user_agent     = env['HTTP_USER_AGENT']
    log.request_uri    = env['REQUEST_URI']
    log.request_method = env['REQUEST_METHOD']
    log.controller     = env['action_dispatch.request.path_parameters'][:controller]
    log.action         = env['action_dispatch.request.path_parameters'][:action]
    log.extra_params   = @extra_params.map{|p| env[p]} unless @extra_params.empty?
  end

  log.save
end