From 77006221f3fe2df582a53af9cb600bd9faedd5b6 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 25 Aug 2011 15:44:53 -0300 Subject: [PATCH] Tiny refactor. --- lib/exception_notifier/notifier.rb | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/exception_notifier/notifier.rb b/lib/exception_notifier/notifier.rb index 70e489df..5d7bb48e 100644 --- a/lib/exception_notifier/notifier.rb +++ b/lib/exception_notifier/notifier.rb @@ -4,6 +4,7 @@ class ExceptionNotifier class Notifier < ActionMailer::Base self.mailer_name = 'exception_notifier' + #Append application view path to the ExceptionNotifier lookup context. self.append_view_path Rails.root.nil? ? "app/views" : "#{Rails.root}/app/views" if defined?(Rails) self.append_view_path "#{File.dirname(__FILE__)}/views" @@ -57,9 +58,9 @@ def exception_notification(env, exception) instance_variable_set("@#{name}", value) end - prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}" - subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}" - subject = subject.length > 120 ? subject[0...120] + "..." : subject + prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}" + subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}" + subject = subject.length > 120 ? subject[0...120] + "..." : subject mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| format.text { render "#{mailer_name}/exception_notification" } @@ -67,28 +68,28 @@ def exception_notification(env, exception) end def background_exception_notification(exception) - - if @notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier } - @options = (@notifier.args.first || {}).reverse_merge(self.class.default_options) - subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}" - + if @notifier = Rails.application.config.middleware.detect{ |x| x.klass == ExceptionNotifier } + @options = (@notifier.args.first || {}).reverse_merge(self.class.default_options) + subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}" + @exception = exception - @backtrace = exception.backtrace || [] - @sections = %w{backtrace} - + @backtrace = exception.backtrace || [] + @sections = %w{backtrace} + mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| format.text { render "#{mailer_name}/background_exception_notification" } end.deliver end end - private def clean_backtrace(exception) - Rails.respond_to?(:backtrace_cleaner) ? - Rails.backtrace_cleaner.send(:filter, exception.backtrace) : - exception.backtrace + if Rails.respond_to?(:backtrace_cleaner) + Rails.backtrace_cleaner.send(:filter, exception.backtrace) + else + exception.backtrace + end end helper_method :inspect_object