Object
# File lib/merb-exceptions/notification.rb, line 14 14: def initialize(details = nil) 15: @details = details || [] 16: Mailer.config = Merb::Plugins.config[:exceptions][:mailer_config] 17: Mailer.delivery_method = Merb::Plugins.config[:exceptions][:mailer_delivery_method] 18: end
# File lib/merb-exceptions/notification.rb, line 20 20: def deliver! 21: deliver_web_hooks! 22: deliver_emails! 23: end
# File lib/merb-exceptions/notification.rb, line 32 32: def deliver_emails! 33: Merb.logger.info "DELIVERING EXCEPTION EMAILS" 34: email_addresses.each do |address| 35: send_email(address) 36: end 37: end
# File lib/merb-exceptions/notification.rb, line 25 25: def deliver_web_hooks! 26: Merb.logger.info "DELIVERING EXCEPTION WEB HOOKS" 27: web_hooks.each do |address| 28: post_hook(address) 29: end 30: end
# File lib/merb-exceptions/notification.rb, line 41 41: def email_addresses; option_as_array(:email_addresses); end
# File lib/merb-exceptions/notification.rb, line 43 43: def environments; option_as_array(:environments); end
# File lib/merb-exceptions/notification.rb, line 45 45: def params 46: @params ||= 47: { 48: 'request_url' => details['url'], 49: 'request_controller' => details['params'][:controller], 50: 'request_action' => details['params'][:action], 51: 'request_params' => details['params'], 52: 'environment' => details['environment'], 53: 'exceptions' => details['exceptions'], 54: 'app_name' => Merb::Plugins.config[:exceptions][:app_name] 55: } 56: end
# File lib/merb-exceptions/notification.rb, line 67 67: def email_body 68: @body ||= begin 69: path = File.join(File.dirname(__FILE__), 'templates', 'email.erb') 70: template = Erubis::Eruby.new(File.open(path,'r') { |f| f.read }) 71: template.result(binding) 72: end 73: end
Used so that we can accept either a single value or array (e.g. of webhooks) in our YAML file.
# File lib/merb-exceptions/notification.rb, line 88 88: def option_as_array(option) 89: value = Merb::Plugins.config[:exceptions][option] 90: case value 91: when Array 92: value.reject { |e| e.nil? } # Don't accept nil values 93: when String 94: [value] 95: else 96: [] 97: end 98: end
# File lib/merb-exceptions/notification.rb, line 60 60: def post_hook(address) 61: Merb.logger.info "- hooking to #{address}" 62: uri = URI.parse(address) 63: uri.path = '/' if uri.path=='' # set a path if one isn't provided to keep Net::HTTP happy 64: Net::HTTP.post_form( uri, params ).body 65: end
# File lib/merb-exceptions/notification.rb, line 75 75: def send_email(address) 76: Merb.logger.info "- emailing to #{address}" 77: email = Mailer.new({ 78: :to => address, 79: :from => Merb::Plugins.config[:exceptions][:email_from], 80: :subject => "[#{Merb::Plugins.config[:exceptions][:app_name]} EXCEPTION]", 81: :text => email_body 82: }) 83: email.deliver! 84: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.