Class: RightSupport::Notifier::Base

Inherits:
Object
  • Object
show all
Includes:
Log::Mixin
Defined in:
lib/right_support/notifiers/base.rb

Overview

base class for notifiers.

Direct Known Subclasses

Airbrake, Logger

Constant Summary

Constants included from Log::Mixin

Log::Mixin::Decorator, Log::Mixin::UNDELEGATED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log::Mixin

default_logger, default_logger=, included

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • options (Hash)

Options Hash (options):

  • :backtrace_limit (Integer)

    as maximum number of stack frames to decode or negative for all. default = 10.

  • :path_blacklist (String|Array)

    for unwanted paths in backtrace. the blacklisted path substring causes the frame to be omitted when it appears anywhere in the traced path. default = none.

  • :notifiable_callback (Proc)

    optional callback to determine if a particular error is worthy of notification. takes an error parameter and returns true if notifiable, false if ignored.

  • :logger (Logger)

    or nil for default



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/right_support/notifiers/base.rb', line 39

def initialize(options)
  options = {
    backtrace_limit: 10,
    notifiable_callback: nil,
    logger: nil
  }.merge(options)
  @notifiable_callback = options[:notifiable_callback]
  @logger = options[:logger]
  @backtrace_decoder = ::RightSupport::Notifier::Utility::BacktraceDecoder.new(
    backtrace_limit: Integer(options[:backtrace_limit]),
    path_blacklist: Array(options[:path_blacklist]))
  @debug_mode = ::ENV['DEBUG_MODE'] == 'true'
end

Instance Attribute Details

#backtrace_decoderObject (readonly)

Returns the value of attribute backtrace_decoder.



27
28
29
# File 'lib/right_support/notifiers/base.rb', line 27

def backtrace_decoder
  @backtrace_decoder
end

Instance Method Details

#debug_mode?TrueClass|FalseClass

Returns true in debug mode.

Returns:

  • (TrueClass|FalseClass)

    true in debug mode



54
55
56
# File 'lib/right_support/notifiers/base.rb', line 54

def debug_mode?
  @debug_mode
end

#notifiable?(e) ⇒ TrueClass|FalseClass

Returns true if the error is notifiable for the current notifier, false to ignore error.

Returns:

  • (TrueClass|FalseClass)

    true if the error is notifiable for the current notifier, false to ignore error.



60
61
62
# File 'lib/right_support/notifiers/base.rb', line 60

def notifiable?(e)
  @notifiable_callback.nil? || @notifiable_callback.call(e)
end

#notify(notification) ⇒ TrueClass

performs a notification.

Parameters:

Returns:

  • (TrueClass)

    always true



69
70
71
# File 'lib/right_support/notifiers/base.rb', line 69

def notify(notification)
  fail 'Must be overridden'
end