Class: Newshound::Exceptions::SolidErrors

Inherits:
Base
  • Object
show all
Defined in:
lib/newshound/exceptions/solid_errors.rb

Constant Summary collapse

LAST_OCCURRED_AT =
"MAX(solid_errors_occurrences.created_at) AS last_occurred_at"
OCCURRENCE_COUNT =
"COUNT(solid_errors_occurrences.id) AS occurrence_count"

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ SolidErrors

Pass unresolved_only: false in exception_source_config to list raw occurrence rows instead of one row per unresolved error.



9
10
11
12
13
# File 'lib/newshound/exceptions/solid_errors.rb', line 9

def initialize(config = {})
  super
  config = config.transform_keys(&:to_sym)
  @unresolved_only = config.fetch(:unresolved_only, true)
end

Instance Method Details

#format_for_banner(exception) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/newshound/exceptions/solid_errors.rb', line 35

def format_for_banner(exception)
  details = parse_exception_details(exception)

  {
    id: banner_id(exception),
    title: details[:title],
    message: details[:message].truncate(100),
    location: details[:location],
    time: details[:time]
  }
end

#format_for_report(exception, number) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/newshound/exceptions/solid_errors.rb', line 24

def format_for_report(exception, number)
  details = parse_exception_details(exception)

  <<~TEXT
    *#{number}. #{details[:title]}*
    • *Time:* #{details[:time]}
    #{format_location(details)}
    #{format_message(details)}
  TEXT
end

#recent(time_range:, limit:) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/newshound/exceptions/solid_errors.rb', line 15

def recent(time_range:, limit:)
  return unresolved_errors(time_range, limit) if @unresolved_only

  ::SolidErrors::Occurrence
    .where("created_at >= ?", time_range.ago)
    .order(created_at: :desc)
    .limit(limit)
end