Class: Newshound::ExceptionReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/newshound/exception_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception_source: nil, configuration: nil, time_range: 24.hours) ⇒ ExceptionReporter

Returns a new instance of ExceptionReporter.



7
8
9
10
11
# File 'lib/newshound/exception_reporter.rb', line 7

def initialize(exception_source: nil, configuration: nil, time_range: 24.hours)
  @configuration = configuration || Newshound.configuration
  @exception_source = resolve_exception_source(exception_source)
  @time_range = time_range
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/newshound/exception_reporter.rb', line 5

def configuration
  @configuration
end

#exception_sourceObject (readonly)

Returns the value of attribute exception_source.



5
6
7
# File 'lib/newshound/exception_reporter.rb', line 5

def exception_source
  @exception_source
end

#time_rangeObject (readonly)

Returns the value of attribute time_range.



5
6
7
# File 'lib/newshound/exception_reporter.rb', line 5

def time_range
  @time_range
end

Instance Method Details

Returns data formatted for the banner UI



30
31
32
33
34
35
36
# File 'lib/newshound/exception_reporter.rb', line 30

def banner_data
  {
    exceptions: recent_exceptions.map { |exception|
      exception_source.format_for_banner(exception)
    }
  }
end

#exception_summaryObject



44
45
46
47
48
# File 'lib/newshound/exception_reporter.rb', line 44

def exception_summary
  recent_exceptions.map.with_index(1) do |ex, i|
    exception_source.format_for_report(ex, i)
  end
end

#formatted_exception_count(format = "Total exceptions: %s") ⇒ Object



38
39
40
41
42
# File 'lib/newshound/exception_reporter.rb', line 38

def formatted_exception_count(
  format = "Total exceptions: %s"
)
  format % recent_exceptions.length
end

#generate_reportObject Also known as: report



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/newshound/exception_reporter.rb', line 13

def generate_report
  return no_exceptions_block if recent_exceptions.empty?

  [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "*🚨 Recent Exceptions (Last 24 Hours)*"
      }
    },
    *format_exceptions
  ]
end