Class: Exceptify::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptify/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, options = {}, clock: Time, hostname: -> { Socket.gethostname }, backtrace_cleaner: nil, **keyword_options) ⇒ Notification

Returns a new instance of Notification.



11
12
13
14
15
16
17
18
# File 'lib/exceptify/notification.rb', line 11

def initialize(exception, options = {}, clock: Time, hostname: -> { Socket.gethostname }, backtrace_cleaner: nil, **keyword_options)
  @exception = exception
  @options = options.merge(keyword_options)
  @clock = clock
  @hostname = hostname
  @backtrace_cleaner = backtrace_cleaner
  @request_context = @options[:request_context] || RequestContext.new(@options[:env])
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



9
10
11
# File 'lib/exceptify/notification.rb', line 9

def exception
  @exception
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/exceptify/notification.rb', line 9

def options
  @options
end

#request_contextObject (readonly)

Returns the value of attribute request_context.



9
10
11
# File 'lib/exceptify/notification.rb', line 9

def request_context
  @request_context
end

Instance Method Details

#app_nameObject



43
44
45
# File 'lib/exceptify/notification.rb', line 43

def app_name
  options[:app_name] || rails_app_name
end

#backtraceObject



28
29
30
31
32
33
# File 'lib/exceptify/notification.rb', line 28

def backtrace
  return [] unless exception.backtrace
  return @backtrace_cleaner.clean_backtrace(exception) if @backtrace_cleaner

  exception.backtrace
end

#controllerObject



51
52
53
# File 'lib/exceptify/notification.rb', line 51

def controller
  request_context.controller
end

#controller_and_actionObject



55
56
57
# File 'lib/exceptify/notification.rb', line 55

def controller_and_action
  request_context.controller_and_action
end

#dataObject



24
25
26
# File 'lib/exceptify/notification.rb', line 24

def data
  request_context.exception_data.merge(options[:data] || {})
end

#envObject



20
21
22
# File 'lib/exceptify/notification.rb', line 20

def env
  request_context.env
end

#env_nameObject



47
48
49
# File 'lib/exceptify/notification.rb', line 47

def env_name
  Rails.env if defined?(::Rails) && ::Rails.respond_to?(:env)
end

#hostnameObject



39
40
41
# File 'lib/exceptify/notification.rb', line 39

def hostname
  @hostname.call
end

#timestampObject



35
36
37
# File 'lib/exceptify/notification.rb', line 35

def timestamp
  @clock.respond_to?(:current) ? @clock.current : @clock.now
end