Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f3c89e3

Browse files
committed
restructure for gem conventions
1 parent 6464214 commit f3c89e3

12 files changed

+41
-49
lines changed

README

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ First, include the ExceptionNotifiable mixin in whichever controller you want
1717
to generate error emails (typically ApplicationController):
1818

1919
class ApplicationController < ActionController::Base
20-
include ExceptionNotifiable
20+
include ExceptionNotification::Notifiable
2121
...
2222
end
2323

2424
Then, specify the email recipients in your environment:
2525

26-
ExceptionNotifier.exception_recipients = %w([email protected] [email protected])
26+
ExceptionNotification::Notifier.exception_recipients = %w([email protected] [email protected])
2727

2828
And that's it! The defaults take care of the rest.
2929

@@ -33,11 +33,11 @@ You can tweak other values to your liking, as well. In your environment file,
3333
just set any or all of the following values:
3434

3535
# defaults to [email protected]
36-
ExceptionNotifier.sender_address =
36+
ExceptionNotification::Notifier.sender_address =
3737
%("Application Error" <[email protected]>)
3838

3939
# defaults to "[ERROR] "
40-
ExceptionNotifier.email_prefix = "[APP] "
40+
ExceptionNotification::Notifier.email_prefix = "[APP] "
4141

4242
Even if you have mixed into ApplicationController you can skip notification in
4343
some controllers by
@@ -76,7 +76,7 @@ requests bugs. To return original functionality add an initializer with:
7676
or just include it per controller that wants it
7777

7878
class MyController < ApplicationController
79-
include ConsiderLocal
79+
include ExceptionNotification::ConsiderLocal
8080
end
8181

8282
== Customization
@@ -97,7 +97,7 @@ access to the following variables:
9797
* @sections: the array of sections to include in the email
9898

9999
You can reorder the sections, or exclude sections completely, by altering the
100-
ExceptionNotifier.sections variable. You can even add new sections that
100+
ExceptionNotification::Notifier.sections variable. You can even add new sections that
101101
describe application-specific data--just add the section's name to the list
102102
(whereever you'd like), and define the corresponding partial. Then, if your
103103
new section requires information that isn't available by default, make sure

exception_notification.gemspec

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'exception_notification'
3+
s.version = '2.3.3.0'
4+
s.authors = ["Jamis Buck", "Josh Peek", "Tim Connor"]
5+
s.date = %q{2010-03-13}
6+
s.summary = "Exception notification by email for Rails apps - 2.3-stable compatible version"
7+
s.email = "[email protected]"
8+
9+
s.files = ['README'] + Dir['lib/**/*'] + Dir['views/**/*']
10+
s.require_path = 'lib'
11+
end

init.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
require "action_mailer"
2-
require "exception_notifier"
3-
require "exception_notifiable"
4-
require "exception_notifier_helper"
5-
require "consider_local"
1+
require "exception_notification"

lib/exception_notification.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "action_mailer"
2+
module ExceptionNotification
3+
autoload :Notifiable, 'exception_notification/notifiable'
4+
autoload :Notifier, 'exception_notification/notifier'
5+
#autoload :NotifierHelper, 'exception_notification/notifier_helper'
6+
autoload :ConsiderLocal, 'exception_notification/consider_local'
7+
end

lib/consider_local.rb renamed to lib/exception_notification/consider_local.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#This didn't belong on ExceptionNotifier and made backtraces worse. To keep original functionality in place
2-
#'ActionController::Base.send :include, ConsiderLocal' or just include in your controller
3-
module ConsiderLocal
2+
#'ActionController::Base.send :include, ExceptionNotification::ConsiderLocal' or just include in your controller
3+
module ExceptionNotification::ConsiderLocal
44
module ClassMethods
55
def self.included(target)
66
require 'ipaddr'

lib/exception_notifiable.rb renamed to lib/exception_notification/notifiable.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1919
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2020
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
module ExceptionNotifiable
21+
module ExceptionNotification::Notifiable
2222
def self.included(target)
2323
target.extend(ClassMethods)
2424
target.skip_exception_notifications false
@@ -61,6 +61,6 @@ def notify_about_exception(exception)
6161
when Proc then deliverer.call(self)
6262
end
6363

64-
ExceptionNotifier.deliver_exception_notification(exception, self, request, data)
64+
ExceptionNotification::Notifier.deliver_exception_notification(exception, self, request, data)
6565
end
6666
end

lib/exception_notifier.rb renamed to lib/exception_notification/notifier.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2121
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2222
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
class ExceptionNotifier < ActionMailer::Base
23+
class ExceptionNotification::Notifier < ActionMailer::Base
2424
self.mailer_name = 'exception_notifier'
25-
self.view_paths << "#{File.dirname(__FILE__)}/../views"
25+
self.view_paths << "#{File.dirname(__FILE__)}/../../views"
2626

2727
@@sender_address = %("Exception Notifier" <[email protected]>)
2828
cattr_accessor :sender_address
@@ -39,15 +39,16 @@ class ExceptionNotifier < ActionMailer::Base
3939
def self.reloadable?() false end
4040

4141
def exception_notification(exception, controller, request, data={})
42+
source = self.class.exception_source(controller)
4243
content_type "text/plain"
4344

44-
subject "#{email_prefix}#{ExceptionNotifier.exception_source(controller)} (#{exception.class}) #{exception.message.inspect}"
45+
subject "#{email_prefix}#{source} (#{exception.class}) #{exception.message.inspect}"
4546

4647
recipients exception_recipients
4748
from sender_address
4849

4950
body data.merge({ :controller => controller, :request => request,
50-
:exception => exception, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
51+
:exception => exception, :exception_source => source, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
5152
:backtrace => sanitize_backtrace(exception.backtrace),
5253
:rails_root => rails_root, :data => data,
5354
:sections => sections })
@@ -71,5 +72,4 @@ def sanitize_backtrace(trace)
7172
def rails_root
7273
@rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s
7374
end
74-
7575
end

lib/exception_notifier_helper.rb renamed to lib/exception_notification/notifier_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2121
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2222
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
module ExceptionNotifierHelper
23+
module ExceptionNotification::NotifierHelper
2424
PARAM_FILTER_REPLACEMENT = "[FILTERED]"
2525

2626
def render_section(section)

test/exception_notifier_helper_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'test_helper'
2-
require 'exception_notifier_helper'
2+
require 'exception_notification/notifier_helper'
33

44
class ExceptionNotifierHelperTest < Test::Unit::TestCase
55

66
class ExceptionNotifierHelperIncludeTarget
7-
include ExceptionNotifierHelper
7+
include ExceptionNotification::NotifierHelper
88
end
99

1010
def setup

test/path_test.rb

-23
This file was deleted.

test/test_helper.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'rubygems'
33
require 'active_support'
44

5-
$:.unshift File.join(File.dirname(__FILE__), '../lib')
6-
75
RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
6+
7+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
8+
require 'exception_notification'

views/exception_notifier/exception_notification.rhtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A <%= @exception.class %> occurred <%= ExceptionNotifier.exception_source(@controller) %>:
1+
A <%= @exception.class %> occurred <%= @exception_source %>:
22

33
<%= @exception.message %>
44
<%= @backtrace.first %>

0 commit comments

Comments
 (0)