Class: ExceptionNotifier::TalkNotifier

Inherits:
Object
  • Object
show all
Includes:
BacktraceCleaner
Defined in:
lib/exception_notifier/talk_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TalkNotifier



8
9
10
11
12
13
# File 'lib/exception_notifier/talk_notifier.rb', line 8

def initialize(options)
  @author_name = options[:author_name] || Socket.gethostname
  @backtrace_depth = options[:backtrace_depth]
  @clean_backtrace = options[:clean_backtrace]
  @hook_url = options[:hook_url]
end

Instance Method Details

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



15
16
17
18
19
20
21
# File 'lib/exception_notifier/talk_notifier.rb', line 15

def call(exception, options={})
  Faraday.post(@hook_url, {
      authorName: @author_name,
      title: "#{exception.class.name}: #{exception.message}",
      text: stringify_exception(exception)
  })
end

#stringify_exception(e) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/exception_notifier/talk_notifier.rb', line 23

def stringify_exception(e)
  if e.backtrace.present?
    backtrace = @clean_backtrace ? clean_backtrace(e) : e.backtrace
    backtrace = backtrace.first(@backtrace_depth) if @backtrace_depth
    ["#{e.class.name}: #{e.message}", 'Backtrace: ', backtrace].join("\n")
  else
    "#{e.class.name}: #{e.message}"
  end
end