Permalink
Browse files

Replace exception_notification plugin with a gem as Rails 2.3-style p…

…lugins are being deprecated
  • Loading branch information...
1 parent cf2c2b6 commit 8b5b339befafb5705924ee0240fd651b74467563 Gabriel Evans committed Jan 20, 2012
View
@@ -44,6 +44,7 @@ gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
+gem 'exception_notification', '~> 2.5.2'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
View
@@ -73,6 +73,8 @@ GEM
database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
+ exception_notification (2.5.2)
+ actionmailer (>= 3.0.4)
execjs (1.3.0)
multi_json (~> 1.0)
factory_girl (2.4.2)
@@ -209,6 +211,7 @@ DEPENDENCIES
cucumber-rails
cucumber-websteps
database_cleaner
+ exception_notification (~> 2.5.2)
factory_girl
formtastic
jquery-rails
@@ -1,81 +0,0 @@
-= Exception Notifier Plugin for Rails
-
-The Exception Notifier plugin provides a mailer object and a default set of
-templates for sending email notifications when errors occur in a Rails
-application. The plugin is configurable, allowing programmers to specify:
-
-* the sender address of the email
-* the recipient addresses
-* the text used to prefix the subject line
-
-The email includes information about the current request, session, and
-environment, and also gives a backtrace of the exception.
-
-== Usage
-
-As of Rails 3 ExceptionNotifier is used as a rack middleware
-
- Whatever::Application.config.middleware.use ExceptionNotifier,
- :email_prefix => "[Whatever] ",
- :sender_address => %{"notifier" <notifier@example.com>},
- :exception_recipients => %w{exceptions@example.com}
-
-== Customization
-
-By default, the notification email includes four parts: request, session,
-environment, and backtrace (in that order). You can customize how each of those
-sections are rendered by placing a partial named for that part in your
-app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
-access to the following variables:
-
-* @controller: the controller that caused the error
-* @request: the current request object
-* @exception: the exception that was raised
-* @backtrace: a sanitized version of the exception's backtrace
-* @data: a hash of optional data values that were passed to the notifier
-* @sections: the array of sections to include in the email
-
-You can reorder the sections, or exclude sections completely, by altering the
-ExceptionNotifier.sections variable. You can even add new sections that
-describe application-specific data--just add the section's name to the list
-(whereever you'd like), and define the corresponding partial. Then, if your
-new section requires information that isn't available by default, make sure
-it is made available to the email using the exception_data macro:
-
- class ApplicationController < ActionController::Base
- before_filter :log_additional_data
- ...
- protected
- def log_additional_data
- request.env["exception_notifier.exception_data"] = {
- :document => @document,
- :person => @person
- }
- end
- ...
- end
-
-In the above case, @document and @person would be made available to the email
-renderer, allowing your new section(s) to access and display them. See the
-existing sections defined by the plugin for examples of how to write your own.
-
-== Notification
-
-After an exception notification has been delivered the rack environment variable
-'exception_notifier.delivered' will be set to +true+.
-
-== Rails 2.3 stable and earlier
-
-If you are running Rails 2.3 then see the branch for that:
-
- http://github.com/rails/exception_notification/tree/2-3-stable
-
-If you are running pre-rack Rails then see this tag:
-
- http://github.com/rails/exception_notification/tree/pre-2-3
-
-== Support and tickets
-
-https://rails.lighthouseapp.com/projects/8995-rails-plugins
-
-Copyright (c) 2005 Jamis Buck, released under the MIT license
@@ -1,11 +0,0 @@
-Gem::Specification.new do |s|
- s.name = 'exception_notification'
- s.version = '1.0.0'
- s.authors = ["Jamis Buck", "Josh Peek"]
- s.date = %q{2010-03-13}
- s.summary = "Exception notification by email for Rails apps"
- s.email = "timocratic@gmail.com"
-
- s.files = ['README'] + Dir['lib/**/*']
- s.require_path = 'lib'
-end
@@ -1,31 +0,0 @@
-require 'action_dispatch'
-require 'exception_notifier/notifier'
-
-class ExceptionNotifier
- def self.default_ignore_exceptions
- [].tap do |exceptions|
- exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
- exceptions << AbstractController::ActionNotFound if defined? AbstractController
- exceptions << ActionController::RoutingError if defined? ActionController
- end
- end
-
- def initialize(app, options = {})
- @app, @options = app, options
- @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
- end
-
- def call(env)
- @app.call(env)
- rescue Exception => exception
- options = (env['exception_notifier.options'] ||= {})
- options.reverse_merge!(@options)
-
- unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
- Notifier.exception_notification(env, exception).deliver
- env['exception_notifier.delivered'] = true
- end
-
- raise exception
- end
-end
@@ -1,83 +0,0 @@
-require 'action_mailer'
-require 'pp'
-
-class ExceptionNotifier
- class Notifier < ActionMailer::Base
- self.mailer_name = 'exception_notifier'
- self.append_view_path "#{File.dirname(__FILE__)}/views"
-
- class << self
- def default_sender_address
- %("Exception Notifier" <exception.notifier@default.com>)
- end
-
- def default_exception_recipients
- []
- end
-
- def default_email_prefix
- "[ERROR] "
- end
-
- def default_sections
- %w(request session environment backtrace)
- end
-
- def default_options
- { :sender_address => default_sender_address,
- :exception_recipients => default_exception_recipients,
- :email_prefix => default_email_prefix,
- :sections => default_sections }
- end
- end
-
- class MissingController
- def method_missing(*args, &block)
- end
- end
-
- def exception_notification(env, exception)
- @env = env
- @exception = exception
- @options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
- @kontroller = env['action_controller.instance'] || MissingController.new
- @request = ActionDispatch::Request.new(env)
- @backtrace = clean_backtrace(exception)
- @sections = @options[:sections]
- data = env['exception_notifier.exception_data'] || {}
-
- data.each do |name, value|
- instance_variable_set("@#{name}", value)
- end
-
- prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}"
- subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
-
- mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
- format.text { render "#{mailer_name}/exception_notification" }
- end
- end
-
- private
-
- def clean_backtrace(exception)
- Rails.respond_to?(:backtrace_cleaner) ?
- Rails.backtrace_cleaner.send(:filter, exception.backtrace) :
- exception.backtrace
- end
-
- helper_method :inspect_object
-
- def inspect_object(object)
- case object
- when Hash, Array
- object.inspect
- when ActionController::Base
- "#{object.controller_name}##{object.action_name}"
- else
- object.to_s
- end
- end
-
- end
-end
@@ -1 +0,0 @@
-<%= raw @backtrace.join("\n") %>
@@ -1,8 +0,0 @@
-<% filtered_env = @request.filtered_env -%>
-<% max = filtered_env.keys.max { |a, b| a.length <=> b.length } -%>
-<% filtered_env.keys.sort.each do |key| -%>
-* <%= raw("%-*s: %s" % [max.length, key, inspect_object(filtered_env[key])]) %>
-<% end -%>
-
-* Process: <%= raw $$ %>
-* Server : <%= raw `hostname -s`.chomp %>
@@ -1,4 +0,0 @@
-* URL : <%= raw @request.url %>
-* IP address: <%= raw @request.remote_ip %>
-* Parameters: <%= raw @request.filtered_parameters.inspect %>
-* Rails root: <%= raw Rails.root %>
@@ -1,2 +0,0 @@
-* session id: <%= raw @request.session['session_id'].inspect.html_safe %>
-* data: <%= raw PP.pp(@request.session, "") %>
@@ -1,3 +0,0 @@
--------------------------------
-<%= raw title.to_s.humanize %>:
--------------------------------
@@ -1,13 +0,0 @@
-A <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
-
- <%= raw @exception.message %>
- <%= raw @backtrace.first %>
-
-<% sections = @sections.map do |section|
- summary = render(section).strip
- unless summary.blank?
- title = render("title", :title => section).strip
- "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
- end
- end %>
-<%= raw sections.join %>

0 comments on commit 8b5b339

Please sign in to comment.