Permalink
Browse files

restructure for gem conventions

  • Loading branch information...
1 parent 6464214 commit f3c89e3542436dd40b28d3bf41dae0baf30b1704 @knzconnor knzconnor committed Mar 13, 2010
View
@@ -17,13 +17,13 @@ First, include the ExceptionNotifiable mixin in whichever controller you want
to generate error emails (typically ApplicationController):
class ApplicationController < ActionController::Base
- include ExceptionNotifiable
+ include ExceptionNotification::Notifiable
...
end
Then, specify the email recipients in your environment:
- ExceptionNotifier.exception_recipients = %w(joe@schmoe.com bill@schmoe.com)
+ ExceptionNotification::Notifier.exception_recipients = %w(joe@schmoe.com bill@schmoe.com)
And that's it! The defaults take care of the rest.
@@ -33,11 +33,11 @@ You can tweak other values to your liking, as well. In your environment file,
just set any or all of the following values:
# defaults to exception.notifier@default.com
- ExceptionNotifier.sender_address =
+ ExceptionNotification::Notifier.sender_address =
%("Application Error" <app.error@myapp.com>)
# defaults to "[ERROR] "
- ExceptionNotifier.email_prefix = "[APP] "
+ ExceptionNotification::Notifier.email_prefix = "[APP] "
Even if you have mixed into ApplicationController you can skip notification in
some controllers by
@@ -76,7 +76,7 @@ requests bugs. To return original functionality add an initializer with:
or just include it per controller that wants it
class MyController < ApplicationController
- include ConsiderLocal
+ include ExceptionNotification::ConsiderLocal
end
== Customization
@@ -97,7 +97,7 @@ access to the following variables:
* @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
+ExceptionNotification::Notifier.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
@@ -0,0 +1,11 @@
+Gem::Specification.new do |s|
+ s.name = 'exception_notification'
+ s.version = '2.3.3.0'
+ s.authors = ["Jamis Buck", "Josh Peek", "Tim Connor"]
+ s.date = %q{2010-03-13}
+ s.summary = "Exception notification by email for Rails apps - 2.3-stable compatible version"
+ s.email = "timocratic@gmail.com"
+
+ s.files = ['README'] + Dir['lib/**/*'] + Dir['views/**/*']
+ s.require_path = 'lib'
+end
View
@@ -1,5 +1 @@
-require "action_mailer"
-require "exception_notifier"
-require "exception_notifiable"
-require "exception_notifier_helper"
-require "consider_local"
+require "exception_notification"
@@ -0,0 +1,7 @@
+require "action_mailer"
+module ExceptionNotification
+ autoload :Notifiable, 'exception_notification/notifiable'
+ autoload :Notifier, 'exception_notification/notifier'
+ #autoload :NotifierHelper, 'exception_notification/notifier_helper'
+ autoload :ConsiderLocal, 'exception_notification/consider_local'
+end
@@ -1,6 +1,6 @@
#This didn't belong on ExceptionNotifier and made backtraces worse. To keep original functionality in place
-#'ActionController::Base.send :include, ConsiderLocal' or just include in your controller
-module ConsiderLocal
+#'ActionController::Base.send :include, ExceptionNotification::ConsiderLocal' or just include in your controller
+module ExceptionNotification::ConsiderLocal
module ClassMethods
def self.included(target)
require 'ipaddr'
@@ -18,7 +18,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-module ExceptionNotifiable
+module ExceptionNotification::Notifiable
def self.included(target)
target.extend(ClassMethods)
target.skip_exception_notifications false
@@ -61,6 +61,6 @@ def notify_about_exception(exception)
when Proc then deliverer.call(self)
end
- ExceptionNotifier.deliver_exception_notification(exception, self, request, data)
+ ExceptionNotification::Notifier.deliver_exception_notification(exception, self, request, data)
end
end
@@ -20,9 +20,9 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-class ExceptionNotifier < ActionMailer::Base
+class ExceptionNotification::Notifier < ActionMailer::Base
self.mailer_name = 'exception_notifier'
- self.view_paths << "#{File.dirname(__FILE__)}/../views"
+ self.view_paths << "#{File.dirname(__FILE__)}/../../views"
@@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
cattr_accessor :sender_address
@@ -39,15 +39,16 @@ class ExceptionNotifier < ActionMailer::Base
def self.reloadable?() false end
def exception_notification(exception, controller, request, data={})
+ source = self.class.exception_source(controller)
content_type "text/plain"
- subject "#{email_prefix}#{ExceptionNotifier.exception_source(controller)} (#{exception.class}) #{exception.message.inspect}"
+ subject "#{email_prefix}#{source} (#{exception.class}) #{exception.message.inspect}"
recipients exception_recipients
from sender_address
body data.merge({ :controller => controller, :request => request,
- :exception => exception, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
+ :exception => exception, :exception_source => source, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
:backtrace => sanitize_backtrace(exception.backtrace),
:rails_root => rails_root, :data => data,
:sections => sections })
@@ -71,5 +72,4 @@ def sanitize_backtrace(trace)
def rails_root
@rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s
end
-
end
@@ -20,7 +20,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-module ExceptionNotifierHelper
+module ExceptionNotification::NotifierHelper
PARAM_FILTER_REPLACEMENT = "[FILTERED]"
def render_section(section)
@@ -1,10 +1,10 @@
require 'test_helper'
-require 'exception_notifier_helper'
+require 'exception_notification/notifier_helper'
class ExceptionNotifierHelperTest < Test::Unit::TestCase
class ExceptionNotifierHelperIncludeTarget
- include ExceptionNotifierHelper
+ include ExceptionNotification::NotifierHelper
end
def setup
View
@@ -1,23 +0,0 @@
-require 'test_helper'
-require 'exception_notifier_helper'
-
-
-class PathTest < Test::Unit::TestCase
- include ExceptionNotifierHelper
-
- EN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
-
- def test_partial_search_paths_include_both_common_extensions
- expected_paths = ["#{EN_ROOT}/views/exception_notifier/_mypartial.html.erb",
- "#{EN_ROOT}/views/exception_notifier/_mypartial.rhtml",
- "./app/views/exception_notifier/_mypartial.html.erb",
- "./app/views/exception_notifier/_mypartial.rhtml"]
- assert_equal(expected_paths.sort, partial_paths("mypartial").sort)
- end
-
- def test_partial_paths_actually_finds_plugin_partial
- assert partial_paths('backtrace').detect {|p| File.exist?(p) }
- end
-
-end
-
View
@@ -2,6 +2,7 @@
require 'rubygems'
require 'active_support'
-$:.unshift File.join(File.dirname(__FILE__), '../lib')
-
RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
+
+$:.unshift File.join(File.dirname(__FILE__), '../lib')
+require 'exception_notification'
@@ -1,4 +1,4 @@
-A <%= @exception.class %> occurred <%= ExceptionNotifier.exception_source(@controller) %>:
+A <%= @exception.class %> occurred <%= @exception_source %>:
<%= @exception.message %>
<%= @backtrace.first %>

0 comments on commit f3c89e3

Please sign in to comment.