Class: MerbExceptions::Notification
- Inherits:
-
Object
- Object
- MerbExceptions::Notification
- Defined in:
- lib/merb_exceptions/notification.rb
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
Instance Method Summary collapse
- #deliver! ⇒ Object
- #deliver_emails! ⇒ Object
- #deliver_web_hooks! ⇒ Object
- #email_addresses ⇒ Object
- #environments ⇒ Object
- #exception ⇒ Object
-
#initialize(details = {}) ⇒ Notification
constructor
A new instance of Notification.
-
#original_exception_class ⇒ Object
this is a horrid hack because I can’t find any easy way to get the exceptions class out of Merb I tried .exception but this seems to recursivly give you Merb exceptions not the original.
- #params ⇒ Object
- #should_deliver_notifications? ⇒ Boolean
- #web_hooks ⇒ Object
Constructor Details
#initialize(details = {}) ⇒ Notification
Returns a new instance of Notification.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/merb_exceptions/notification.rb', line 9 def initialize(details = {}) @details = details @config = { :web_hooks => [], :email_addresses => [], :app_name => "Merb Application", :email_from => "[email protected]", :environments => ['production'] }.merge(Merb::Plugins.config[:exceptions] || {}) end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
7 8 9 |
# File 'lib/merb_exceptions/notification.rb', line 7 def details @details end |
Instance Method Details
#deliver! ⇒ Object
20 21 22 23 |
# File 'lib/merb_exceptions/notification.rb', line 20 def deliver! deliver_web_hooks! deliver_emails! end |
#deliver_emails! ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/merb_exceptions/notification.rb', line 33 def deliver_emails! return unless should_deliver_notifications? Merb.logger.info "DELIVERING EXCEPTION EMAILS" email_addresses.each do |address| send_notification_email(address) end end |
#deliver_web_hooks! ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/merb_exceptions/notification.rb', line 25 def deliver_web_hooks! return unless should_deliver_notifications? Merb.logger.info "DELIVERING EXCEPTION WEB HOOKS" web_hooks.each do |address| post_hook(address) end end |
#email_addresses ⇒ Object
43 |
# File 'lib/merb_exceptions/notification.rb', line 43 def email_addresses; option_as_array(:email_addresses); end |
#environments ⇒ Object
45 |
# File 'lib/merb_exceptions/notification.rb', line 45 def environments; option_as_array(:environments); end |
#exception ⇒ Object
47 48 49 |
# File 'lib/merb_exceptions/notification.rb', line 47 def exception @details['exception'] end |
#original_exception_class ⇒ Object
this is a horrid hack because I can’t find any easy way to get the exceptions class out of Merb I tried .exception but this seems to recursivly give you Merb exceptions not the original
57 58 59 |
# File 'lib/merb_exceptions/notification.rb', line 57 def original_exception_class exception.to_yaml.match(/^exception: !ruby\/exception:(.+)/)[1] rescue 'N/A' end |
#params ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/merb_exceptions/notification.rb', line 61 def params { 'request_url' => details['url'], 'request_controller' => details['params'][:controller], 'request_action' => details['params'][:action], 'request_params' => details['params'], 'request_status_code' => exception.class::STATUS, 'exception_name' => exception.name, 'exception_message' => exception., 'exception_backtrace' => (exception.backtrace or []).join("\n"), 'merb_exception_class' => exception.class, 'original_exception_class' => original_exception_class, 'environment' => details['environment'] } end |
#should_deliver_notifications? ⇒ Boolean
51 52 53 |
# File 'lib/merb_exceptions/notification.rb', line 51 def should_deliver_notifications? environments.include? Merb.env end |
#web_hooks ⇒ Object
41 |
# File 'lib/merb_exceptions/notification.rb', line 41 def web_hooks; option_as_array(:web_hooks); end |