Class: ExceptionNotifier
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- ExceptionNotifier
- Defined in:
- lib/exception_notifier.rb
Class Method Summary collapse
- .catch_all(verbose = false) ⇒ Object
- .configure_exception_notifier {|@@config| ... } ⇒ Object
-
.exception_to_filenames(exception) ⇒ Object
Returns an array of potential filenames to look for eg.
-
.filenamify(str) ⇒ Object
Converts Stringified Class Names to acceptable filename handles with underscores.
-
.get_view_path(file_name, verbose = false) ⇒ Object
Check the usual suspects.
-
.get_view_path_for_class(exception, verbose = false) ⇒ Object
What is the path of the file we will render to the user based on a given exception class?.
-
.get_view_path_for_status_code(status_cd, verbose = false) ⇒ Object
What is the path of the file we will render to the user based on a given status code?.
- .reloadable? ⇒ Boolean
Instance Method Summary collapse
- #background_exception_notification(exception, data = {}, the_blamed = nil) ⇒ Object
- #exception_notification(exception, controller = nil, request = nil, data = {}, the_blamed = nil) ⇒ Object
Class Method Details
.catch_all(verbose = false) ⇒ Object
85 86 87 88 |
# File 'lib/exception_notifier.rb', line 85 def self.catch_all(verbose = false) puts "[CATCH ALL INVOKED] #{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/500.html" if verbose "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/500.html" end |
.configure_exception_notifier {|@@config| ... } ⇒ Object
31 32 33 |
# File 'lib/exception_notifier.rb', line 31 def self.configure_exception_notifier(&block) yield @@config end |
.exception_to_filenames(exception) ⇒ Object
Returns an array of potential filenames to look for eg. For the Exception Class - SuperExceptionNotifier::CustomExceptionClasses::MethodDisabled the filename handles are:
super_exception_notifier_custom_exception_classes_method_disabled
method_disabled
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/exception_notifier.rb', line 44 def self.exception_to_filenames(exception) filenames = [] e = exception.to_s filenames << ExceptionNotifier.filenamify(e) last_colon = e.rindex(':') unless last_colon.nil? filenames << ExceptionNotifier.filenamify(e[(last_colon + 1)..(e.length - 1)]) end filenames end |
.filenamify(str) ⇒ Object
Converts Stringified Class Names to acceptable filename handles with underscores
57 58 59 |
# File 'lib/exception_notifier.rb', line 57 def self.filenamify(str) str.delete(':').gsub( /([A-Za-z])([A-Z])/, '\1' << '_' << '\2').downcase end |
.get_view_path(file_name, verbose = false) ⇒ Object
Check the usual suspects
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/exception_notifier.rb', line 91 def self.get_view_path(file_name, verbose = false) if File.exist?("#{RAILS_ROOT}/public/#{file_name}.html") puts "[FOUND FILE] #{RAILS_ROOT}/public/#{file_name}.html" if verbose "#{RAILS_ROOT}/public/#{file_name}.html" elsif !config[:view_path].nil? && File.exist?("#{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html.erb") puts "[FOUND FILE] #{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html.erb" if verbose "#{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html.erb" elsif !config[:view_path].nil? && File.exist?("#{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html") puts "[FOUND FILE] #{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html" if verbose "#{RAILS_ROOT}/#{config[:view_path]}/#{file_name}.html" elsif File.exist?("#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html.erb") puts "[FOUND FILE] #{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html.erb" if verbose "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html.erb" elsif File.exist?("#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html") #ExceptionNotifierHelper::COMPAT_MODE ? "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html" : "#{status_cd}.html" puts "[FOUND FILE] #{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html" if verbose "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html" else nil end end |
.get_view_path_for_class(exception, verbose = false) ⇒ Object
What is the path of the file we will render to the user based on a given exception class?
76 77 78 79 80 81 82 83 |
# File 'lib/exception_notifier.rb', line 76 def self.get_view_path_for_class(exception, verbose = false) return self.catch_all if exception.nil? return self.catch_all unless exception.is_a?(StandardError) || exception.is_a?(Class) # For some reason exception.is_a?(Class) works in console, but not when running in mongrel (ALWAYS returns false)?!?!? filepaths = ExceptionNotifier.exception_to_filenames(exception).map do |file| ExceptionNotifier.get_view_path(file, verbose) end.compact filepaths.empty? ? self.catch_all(verbose) : filepaths.first end |
.get_view_path_for_status_code(status_cd, verbose = false) ⇒ Object
What is the path of the file we will render to the user based on a given status code?
62 63 64 65 66 |
# File 'lib/exception_notifier.rb', line 62 def self.get_view_path_for_status_code(status_cd, verbose = false) file_name = ExceptionNotifier.get_view_path(status_cd, verbose) #ExceptionNotifierHelper::COMPAT_MODE ? "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/500.html" : "500.html" file_name.nil? ? self.catch_all(verbose) : file_name end |
.reloadable? ⇒ Boolean
37 |
# File 'lib/exception_notifier.rb', line 37 def self.reloadable?() false end |
Instance Method Details
#background_exception_notification(exception, data = {}, the_blamed = nil) ⇒ Object
126 127 128 |
# File 'lib/exception_notifier.rb', line 126 def background_exception_notification(exception, data = {}, the_blamed = nil) exception_notification(exception, nil, nil, data, the_blamed) end |
#exception_notification(exception, controller = nil, request = nil, data = {}, the_blamed = nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/exception_notifier.rb', line 113 def exception_notification(exception, controller = nil, request = nil, data={}, the_blamed=nil) body_hash = error_environment_data_hash(exception, controller, request, data, the_blamed) #Prefer to have custom, potentially HTML email templates available #content_type "text/plain" recipients config[:exception_recipients] from config[:sender_address] request.session.inspect unless request.nil? # Ensure session data is loaded (Rails 2.3 lazy-loading) subject "#{config[:subject_prepend]}#{body_hash[:location]} (#{exception.class}) #{exception..inspect}#{config[:subject_append]}" body body_hash end |