Class: Denouncer::Notifiers::BaseNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/denouncer/notifiers/base_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BaseNotifier

Returns a new instance of BaseNotifier.



8
9
10
11
12
13
14
# File 'lib/denouncer/notifiers/base_notifier.rb', line 8

def initialize(options)
  if options[:application_name].nil? || !options[:application_name].is_a?(String)
    raise "Invalid configuration hash: No valid :application_name given"
  end
  opts = set_configuration!(options).dup
  @config = opts
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/denouncer/notifiers/base_notifier.rb', line 6

def config
  @config
end

Instance Method Details

#get_current_timestampObject

Returns the current timestamp in utc is8601 format



17
18
19
# File 'lib/denouncer/notifiers/base_notifier.rb', line 17

def get_current_timestamp
  Time.now.utc
end

#get_error_cause(error) ⇒ Object

returns the given error’s cause if available



22
23
24
25
26
27
28
# File 'lib/denouncer/notifiers/base_notifier.rb', line 22

def get_error_cause(error)
  if error.respond_to? :cause
    error.cause
  else
    nil
  end
end

#nameString

Returns the name for the notifier.

Returns:

  • (String)

    the name for the notifier



31
32
33
# File 'lib/denouncer/notifiers/base_notifier.rb', line 31

def name
  raise NotImplementedException("This method needs to be implemented in a sub-class!")
end

#notify(error, metadata = nil) ⇒ Object

Sends a notification.

Parameters:

  • error (StandardError)
  • metadata (Hash) (defaults to: nil)


43
44
45
# File 'lib/denouncer/notifiers/base_notifier.rb', line 43

def notify(error,  = nil)
  raise NotImplementedException("This method needs to be implemented in a sub-class!")
end

#set_configuration!(options) ⇒ Object



35
36
37
# File 'lib/denouncer/notifiers/base_notifier.rb', line 35

def set_configuration!(options)
  raise NotImplementedException("This method needs to be implemented in a sub-class!")
end