Class: Rusen::Notifier
- Inherits:
-
Object
- Object
- Rusen::Notifier
- Defined in:
- lib/rusen/notifier.rb
Instance Method Summary collapse
-
#initialize(settings) ⇒ Notifier
constructor
A new instance of Notifier.
-
#notify(exception, request = {}, environment = {}, session = {}) ⇒ Object
Sends a notification to the configured outputs.
- #register(notifier_class) ⇒ Object
Constructor Details
#initialize(settings) ⇒ Notifier
Returns a new instance of Notifier.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rusen/notifier.rb', line 8 def initialize(settings) @settings = settings @notifiers = [] @settings.outputs.each do |ident| ident = Notifiers.check_deprecation(ident) # For notifiers bundled in this gem klass = Notifiers.load_klass(ident) if klass.nil? Notifiers.constants.each do |constant| klass = Notifiers.const_get(constant) next unless klass.is_a?(Class) break if ident == klass.identification_symbol klass = nil end end raise "Unable to load Output Notifier identified by: #{ident}" if klass.nil? || !klass.is_a?(Class) register(klass) end end |
Instance Method Details
#notify(exception, request = {}, environment = {}, session = {}) ⇒ Object
Sends a notification to the configured outputs.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rusen/notifier.rb', line 39 def notify(exception, request = {}, environment = {}, session = {}) begin notification = Notification.new(exception, request, environment, session) @notifiers.each do |notifier| notifier.notify(notification) end # We need to ignore all the exceptions thrown by the notifiers. rescue Exception warn("Rusen: Some or all the notifiers failed to sent the notification.") end end |
#register(notifier_class) ⇒ Object
29 30 31 |
# File 'lib/rusen/notifier.rb', line 29 def register(notifier_class) @notifiers << notifier_class.new(@settings) end |