Module: Denouncer
- Defined in:
- lib/denouncer.rb,
lib/denouncer/version.rb,
lib/denouncer/notifiers.rb,
lib/denouncer/notifiers/amqp_notifier.rb,
lib/denouncer/notifiers/base_notifier.rb,
lib/denouncer/notifiers/smtp_notifier.rb,
lib/denouncer/notifiers/console_notifier.rb,
lib/denouncer/notifiers/airbrake_notifier.rb,
lib/denouncer/notifiers/honeybadger_notifier.rb
Defined Under Namespace
Modules: Notifiers
Constant Summary collapse
- DEFAULT_NOTIFIER =
:smtp
- VERSION =
"0.6.0"
- @@notifiers =
nil
Class Method Summary collapse
-
.config ⇒ Object
Returns the current notifier’s config or nil if not configured.
-
.configure(options) ⇒ Object
Configures denouncer using the specified configuration hash.
- .is_configured? ⇒ Boolean
-
.notify(error, metadata = nil) ⇒ Object
Sends a notification using the configured notifier.
-
.notify!(error, metadata = nil) ⇒ Object
Sends a notification and raises the given error on return.
- .reset_configuration ⇒ Object
Class Method Details
.config ⇒ Object
Returns the current notifier’s config or nil if not configured.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/denouncer.rb', line 36 def self.config return nil unless is_configured? if notifiers.count == 1 notifiers.first.config else conf = {} conf[:application_name] = notifiers.first.config[:application_name] conf[:notifiers] = Array.new conf[:configurations] = {} notifiers.each do |notif| conf[:notifiers] << notif.name.to_sym conf[:configurations][notif.name.to_sym] = notif.config end conf end end |
.configure(options) ⇒ Object
Configures denouncer using the specified configuration hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/denouncer.rb', line 13 def self.configure() check_base_configuration! if [:notifier].nil? && [:notifiers].nil? [:notifier] = DEFAULT_NOTIFIER end unless [:notifiers].nil? [:notifiers] = [:notifiers].map { |n| n.to_sym } end initialize_notifiers end |
.is_configured? ⇒ Boolean
31 32 33 |
# File 'lib/denouncer.rb', line 31 def self.is_configured? !notifiers.nil? end |
.notify(error, metadata = nil) ⇒ Object
Sends a notification using the configured notifier.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/denouncer.rb', line 57 def self.notify(error, = nil) if is_configured? # ATTENTION: this ensures that no exceptions are lost when denouncer is not working as expected!!! # This is worth the downside of denouncer debugging thougths. begin notifiers.each do |notif| notif.notify error, end return true rescue => err puts "An error occured while sending an exception notification via denouncer! Error: #{err.}, Backtrace: #{err.backtrace}" end else return false end end |
.notify!(error, metadata = nil) ⇒ Object
Sends a notification and raises the given error on return
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/denouncer.rb', line 79 def self.notify!(error, = nil) if is_configured? notifiers.each do |notif| notif.notify error, end end rescue => err puts "An error occured while sending an exception notification via denouncer! Error: #{err.}, Backtrace: #{err.backtrace}" ensure raise error end |
.reset_configuration ⇒ Object
27 28 29 |
# File 'lib/denouncer.rb', line 27 def self.reset_configuration @@notifiers = nil end |