ruby-activeldap 0.8.3 → 0.8.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/CHANGES +431 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +58 -0
  4. data/README +104 -0
  5. data/Rakefile +165 -0
  6. data/TODO +22 -0
  7. data/benchmark/bench-al.rb +202 -0
  8. data/benchmark/config.yaml.sample +5 -0
  9. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  10. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  11. data/examples/al-admin/README +182 -0
  12. data/examples/al-admin/Rakefile +10 -0
  13. data/examples/al-admin/app/controllers/account_controller.rb +50 -0
  14. data/examples/al-admin/app/controllers/application.rb +15 -0
  15. data/examples/al-admin/app/controllers/directory_controller.rb +22 -0
  16. data/examples/al-admin/app/controllers/users_controller.rb +38 -0
  17. data/examples/al-admin/app/controllers/welcome_controller.rb +4 -0
  18. data/examples/al-admin/app/helpers/account_helper.rb +2 -0
  19. data/examples/al-admin/app/helpers/application_helper.rb +6 -0
  20. data/examples/al-admin/app/helpers/directory_helper.rb +2 -0
  21. data/examples/al-admin/app/helpers/users_helper.rb +13 -0
  22. data/examples/al-admin/app/helpers/welcome_helper.rb +2 -0
  23. data/examples/al-admin/app/models/entry.rb +19 -0
  24. data/examples/al-admin/app/models/ldap_user.rb +49 -0
  25. data/examples/al-admin/app/models/user.rb +91 -0
  26. data/examples/al-admin/app/views/account/login.rhtml +12 -0
  27. data/examples/al-admin/app/views/account/sign_up.rhtml +22 -0
  28. data/examples/al-admin/app/views/directory/index.rhtml +5 -0
  29. data/examples/al-admin/app/views/directory/populate.rhtml +2 -0
  30. data/examples/al-admin/app/views/layouts/application.rhtml +41 -0
  31. data/examples/al-admin/app/views/users/_attribute_information.rhtml +22 -0
  32. data/examples/al-admin/app/views/users/_entry.rhtml +12 -0
  33. data/examples/al-admin/app/views/users/_form.rhtml +29 -0
  34. data/examples/al-admin/app/views/users/_object_class_information.rhtml +23 -0
  35. data/examples/al-admin/app/views/users/edit.rhtml +10 -0
  36. data/examples/al-admin/app/views/users/index.rhtml +9 -0
  37. data/examples/al-admin/app/views/users/show.rhtml +3 -0
  38. data/examples/al-admin/app/views/welcome/index.rhtml +16 -0
  39. data/examples/al-admin/config/boot.rb +45 -0
  40. data/examples/al-admin/config/database.yml.example +19 -0
  41. data/examples/al-admin/config/environment.rb +68 -0
  42. data/examples/al-admin/config/environments/development.rb +21 -0
  43. data/examples/al-admin/config/environments/production.rb +18 -0
  44. data/examples/al-admin/config/environments/test.rb +19 -0
  45. data/examples/al-admin/config/ldap.yml.example +21 -0
  46. data/examples/al-admin/config/routes.rb +26 -0
  47. data/examples/al-admin/db/migrate/001_create_users.rb +16 -0
  48. data/examples/al-admin/lib/accept_http_rails_relative_url_root.rb +9 -0
  49. data/examples/al-admin/lib/authenticated_system.rb +131 -0
  50. data/examples/al-admin/lib/authenticated_test_helper.rb +113 -0
  51. data/examples/al-admin/lib/tasks/gettext.rake +35 -0
  52. data/examples/al-admin/po/en/al-admin.po +190 -0
  53. data/examples/al-admin/po/ja/al-admin.po +190 -0
  54. data/examples/al-admin/po/nl/al-admin.po +202 -0
  55. data/examples/al-admin/public/.htaccess +40 -0
  56. data/examples/al-admin/public/404.html +30 -0
  57. data/examples/al-admin/public/500.html +30 -0
  58. data/examples/al-admin/public/dispatch.cgi +10 -0
  59. data/examples/al-admin/public/dispatch.fcgi +24 -0
  60. data/examples/al-admin/public/dispatch.rb +10 -0
  61. data/examples/al-admin/public/favicon.ico +0 -0
  62. data/examples/al-admin/public/images/rails.png +0 -0
  63. data/examples/al-admin/public/javascripts/application.js +2 -0
  64. data/examples/al-admin/public/javascripts/controls.js +833 -0
  65. data/examples/al-admin/public/javascripts/dragdrop.js +942 -0
  66. data/examples/al-admin/public/javascripts/effects.js +1088 -0
  67. data/examples/al-admin/public/javascripts/prototype.js +2515 -0
  68. data/examples/al-admin/public/robots.txt +1 -0
  69. data/examples/al-admin/public/stylesheets/rails.css +35 -0
  70. data/examples/al-admin/public/stylesheets/screen.css +52 -0
  71. data/examples/al-admin/script/about +3 -0
  72. data/examples/al-admin/script/breakpointer +3 -0
  73. data/examples/al-admin/script/console +3 -0
  74. data/examples/al-admin/script/destroy +3 -0
  75. data/examples/al-admin/script/generate +3 -0
  76. data/examples/al-admin/script/performance/benchmarker +3 -0
  77. data/examples/al-admin/script/performance/profiler +3 -0
  78. data/examples/al-admin/script/plugin +3 -0
  79. data/examples/al-admin/script/process/inspector +3 -0
  80. data/examples/al-admin/script/process/reaper +3 -0
  81. data/examples/al-admin/script/process/spawner +3 -0
  82. data/examples/al-admin/script/runner +3 -0
  83. data/examples/al-admin/script/server +3 -0
  84. data/examples/al-admin/test/fixtures/users.yml +9 -0
  85. data/examples/al-admin/test/functional/account_controller_test.rb +24 -0
  86. data/examples/al-admin/test/functional/directory_controller_test.rb +18 -0
  87. data/examples/al-admin/test/functional/users_controller_test.rb +18 -0
  88. data/examples/al-admin/test/functional/welcome_controller_test.rb +18 -0
  89. data/examples/al-admin/test/run-test.sh +3 -0
  90. data/examples/al-admin/test/test_helper.rb +28 -0
  91. data/examples/al-admin/test/unit/user_test.rb +13 -0
  92. data/examples/al-admin/vendor/plugins/exception_notification/README +111 -0
  93. data/examples/al-admin/vendor/plugins/exception_notification/init.rb +1 -0
  94. data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifiable.rb +99 -0
  95. data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +67 -0
  96. data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +77 -0
  97. data/examples/al-admin/vendor/plugins/exception_notification/test/exception_notifier_helper_test.rb +61 -0
  98. data/examples/al-admin/vendor/plugins/exception_notification/test/test_helper.rb +7 -0
  99. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_backtrace.rhtml +1 -0
  100. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +7 -0
  101. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_inspect_model.rhtml +16 -0
  102. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +3 -0
  103. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml +2 -0
  104. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_title.rhtml +3 -0
  105. data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/exception_notification.rhtml +6 -0
  106. data/examples/config.yaml.example +5 -0
  107. data/examples/example.der +0 -0
  108. data/examples/example.jpg +0 -0
  109. data/examples/groupadd +41 -0
  110. data/examples/groupdel +35 -0
  111. data/examples/groupls +49 -0
  112. data/examples/groupmod +42 -0
  113. data/examples/lpasswd +55 -0
  114. data/examples/objects/group.rb +13 -0
  115. data/examples/objects/ou.rb +4 -0
  116. data/examples/objects/user.rb +20 -0
  117. data/examples/ouadd +38 -0
  118. data/examples/useradd +45 -0
  119. data/examples/useradd-binary +50 -0
  120. data/examples/userdel +34 -0
  121. data/examples/userls +50 -0
  122. data/examples/usermod +42 -0
  123. data/examples/usermod-binary-add +47 -0
  124. data/examples/usermod-binary-add-time +51 -0
  125. data/examples/usermod-binary-del +48 -0
  126. data/examples/usermod-lang-add +43 -0
  127. data/lib/active_ldap.rb +978 -0
  128. data/lib/active_ldap/adapter/base.rb +512 -0
  129. data/lib/active_ldap/adapter/ldap.rb +233 -0
  130. data/lib/active_ldap/adapter/ldap_ext.rb +69 -0
  131. data/lib/active_ldap/adapter/net_ldap.rb +290 -0
  132. data/lib/active_ldap/adapter/net_ldap_ext.rb +29 -0
  133. data/lib/active_ldap/association/belongs_to.rb +47 -0
  134. data/lib/active_ldap/association/belongs_to_many.rb +42 -0
  135. data/lib/active_ldap/association/collection.rb +83 -0
  136. data/lib/active_ldap/association/has_many.rb +31 -0
  137. data/lib/active_ldap/association/has_many_utils.rb +35 -0
  138. data/lib/active_ldap/association/has_many_wrap.rb +46 -0
  139. data/lib/active_ldap/association/proxy.rb +102 -0
  140. data/lib/active_ldap/associations.rb +172 -0
  141. data/lib/active_ldap/attributes.rb +211 -0
  142. data/lib/active_ldap/base.rb +1256 -0
  143. data/lib/active_ldap/callbacks.rb +19 -0
  144. data/lib/active_ldap/command.rb +48 -0
  145. data/lib/active_ldap/configuration.rb +114 -0
  146. data/lib/active_ldap/connection.rb +234 -0
  147. data/lib/active_ldap/distinguished_name.rb +250 -0
  148. data/lib/active_ldap/escape.rb +12 -0
  149. data/lib/active_ldap/get_text/parser.rb +142 -0
  150. data/lib/active_ldap/get_text_fallback.rb +53 -0
  151. data/lib/active_ldap/get_text_support.rb +12 -0
  152. data/lib/active_ldap/helper.rb +23 -0
  153. data/lib/active_ldap/ldap_error.rb +74 -0
  154. data/lib/active_ldap/object_class.rb +93 -0
  155. data/lib/active_ldap/operations.rb +419 -0
  156. data/lib/active_ldap/populate.rb +44 -0
  157. data/lib/active_ldap/schema.rb +427 -0
  158. data/lib/active_ldap/timeout.rb +75 -0
  159. data/lib/active_ldap/timeout_stub.rb +17 -0
  160. data/lib/active_ldap/user_password.rb +93 -0
  161. data/lib/active_ldap/validations.rb +112 -0
  162. data/po/en/active-ldap.po +3011 -0
  163. data/po/ja/active-ldap.po +3044 -0
  164. data/rails/plugin/active_ldap/README +54 -0
  165. data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +7 -0
  166. data/rails/plugin/active_ldap/generators/scaffold_al/templates/ldap.yml +21 -0
  167. data/rails/plugin/active_ldap/init.rb +19 -0
  168. data/test/al-test-utils.rb +362 -0
  169. data/test/command.rb +62 -0
  170. data/test/config.yaml.sample +6 -0
  171. data/test/run-test.rb +31 -0
  172. data/test/test-unit-ext.rb +4 -0
  173. data/test/test-unit-ext/always-show-result.rb +28 -0
  174. data/test/test-unit-ext/backtrace-filter.rb +17 -0
  175. data/test/test-unit-ext/long-display-for-emacs.rb +25 -0
  176. data/test/test-unit-ext/priority.rb +163 -0
  177. metadata +211 -4
@@ -0,0 +1 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
@@ -0,0 +1,35 @@
1
+ .fieldWithErrors {
2
+ padding: 2px;
3
+ background-color: red;
4
+ display: table;
5
+ }
6
+
7
+ #errorExplanation {
8
+ width: 400px;
9
+ border: 2px solid red;
10
+ padding: 7px;
11
+ padding-bottom: 12px;
12
+ margin-bottom: 20px;
13
+ background-color: #f0f0f0;
14
+ }
15
+
16
+ #errorExplanation h2 {
17
+ text-align: left;
18
+ font-weight: bold;
19
+ padding: 5px 5px 5px 15px;
20
+ font-size: 12px;
21
+ margin: -7px;
22
+ background-color: #c00;
23
+ color: #fff;
24
+ }
25
+
26
+ #errorExplanation p {
27
+ color: #333;
28
+ margin-bottom: 0;
29
+ padding: 5px;
30
+ }
31
+
32
+ #errorExplanation ul li {
33
+ font-size: 12px;
34
+ list-style: square;
35
+ }
@@ -0,0 +1,52 @@
1
+ body
2
+ {
3
+ margin: 0.5em 1.5em;
4
+ }
5
+
6
+ table, tr, th, td
7
+ {
8
+ border: 1px solid black;
9
+ }
10
+
11
+ p.notice
12
+ {
13
+ color: green;
14
+ }
15
+
16
+ div.entry
17
+ {
18
+ padding-bottom: 2em;
19
+ border-bottom: 1px solid black;
20
+ }
21
+
22
+ div.entry table
23
+ {
24
+ margin-left: 3em;
25
+ }
26
+
27
+ div.entry table tbody th
28
+ {
29
+ text-align: left;
30
+ }
31
+
32
+ div.object-class-information
33
+ {
34
+ margin: 1em 5em;
35
+ padding: 0px 1em;
36
+ }
37
+
38
+ div.footer
39
+ {
40
+ margin-top: 0.5em;
41
+ border-top: 1px solid gray;
42
+ }
43
+
44
+ div.footer div.links
45
+ {
46
+ float: left;
47
+ }
48
+
49
+ div.system-info
50
+ {
51
+ text-align: right;
52
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/breakpointer'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,9 @@
1
+ quentin:
2
+ id: 1
3
+ login: quentin
4
+ updated_at: <%= 5.days.ago.to_s :db %>
5
+
6
+ aaron:
7
+ id: 2
8
+ login: aaron
9
+ updated_at: <%= 1.days.ago.to_s :db %>
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'account_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class AccountController; def rescue_action(e) raise e end; end
6
+
7
+ class AccountControllerTest < Test::Unit::TestCase
8
+ # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9
+ # Then, you can remove it from this and the units test.
10
+ include AuthenticatedTestHelper
11
+
12
+ fixtures :users
13
+
14
+ def setup
15
+ @controller = AccountController.new
16
+ @request = ActionController::TestRequest.new
17
+ @response = ActionController::TestResponse.new
18
+ end
19
+
20
+ # Replace this with your real tests.
21
+ def test_truth
22
+ assert true
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'directory_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class DirectoryController; def rescue_action(e) raise e end; end
6
+
7
+ class DirectoryControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = DirectoryController.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ # Replace this with your real tests.
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'users_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class UsersController; def rescue_action(e) raise e end; end
6
+
7
+ class UsersControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = UsersController.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ # Replace this with your real tests.
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'welcome_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class WelcomeController; def rescue_action(e) raise e end; end
6
+
7
+ class WelcomeControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = WelcomeController.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ # Replace this with your real tests.
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ rake test
@@ -0,0 +1,28 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class Test::Unit::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ self.use_transactional_fixtures = true
19
+
20
+ # Instantiated fixtures are slow, but give you @david where otherwise you
21
+ # would need people(:david). If you don't want to migrate your existing
22
+ # test cases which use the @david style and don't mind the speed hit (each
23
+ # instantiated fixtures translates to a database query per test method),
24
+ # then set this back to true.
25
+ self.use_instantiated_fixtures = false
26
+
27
+ # Add more helper methods to be used by all tests here...
28
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class UserTest < Test::Unit::TestCase
4
+ # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.
5
+ # Then, you can remove it from this and the functional test.
6
+ include AuthenticatedTestHelper
7
+ fixtures :users
8
+
9
+ # Replace this with your real tests.
10
+ def test_truth
11
+ assert true
12
+ end
13
+ end
@@ -0,0 +1,111 @@
1
+ = Exception Notifier Plugin for Rails
2
+
3
+ The Exception Notifier plugin provides a mailer object and a default set of
4
+ templates for sending email notifications when errors occur in a Rails
5
+ application. The plugin is configurable, allowing programmers to specify:
6
+
7
+ * the sender address of the email
8
+ * the recipient addresses
9
+ * the text used to prefix the subject line
10
+
11
+ The email includes information about the current request, session, and
12
+ environment, and also gives a backtrace of the exception.
13
+
14
+ == Usage
15
+
16
+ First, include the ExceptionNotifiable mixin in whichever controller you want
17
+ to generate error emails (typically ApplicationController):
18
+
19
+ class ApplicationController < ActionController::Base
20
+ include ExceptionNotifiable
21
+ ...
22
+ end
23
+
24
+ Then, specify the email recipients in your environment:
25
+
26
+ ExceptionNotifier.exception_recipients = %w(joe@schmoe.com bill@schmoe.com)
27
+
28
+ And that's it! The defaults take care of the rest.
29
+
30
+ == Configuration
31
+
32
+ You can tweak other values to your liking, as well. In your environment file,
33
+ just set any or all of the following values:
34
+
35
+ # defaults to exception.notifier@default.com
36
+ ExceptionNotifier.sender_address =
37
+ %("Application Error" <app.error@myapp.com>)
38
+
39
+ # defaults to "[ERROR] "
40
+ ExceptionNotifier.email_prefix = "[APP] "
41
+
42
+ Email notifications will only occur when the IP address is determined not to
43
+ be local. You can specify certain addresses to always be local so that you'll
44
+ get a detailed error instead of the generic error page. You do this in your
45
+ controller (or even per-controller):
46
+
47
+ consider_local "64.72.18.143", "14.17.21.25"
48
+
49
+ You can specify subnet masks as well, so that all matching addresses are
50
+ considered local:
51
+
52
+ consider_local "64.72.18.143/24"
53
+
54
+ The address "127.0.0.1" is always considered local. If you want to completely
55
+ reset the list of all addresses (for instance, if you wanted "127.0.0.1" to
56
+ NOT be considered local), you can simply do, somewhere in your controller:
57
+
58
+ local_addresses.clear
59
+
60
+ == Customization
61
+
62
+ By default, the notification email includes four parts: request, session,
63
+ environment, and backtrace (in that order). You can customize how each of those
64
+ sections are rendered by placing a partial named for that part in your
65
+ app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
66
+ access to the following variables:
67
+
68
+ * @controller: the controller that caused the error
69
+ * @request: the current request object
70
+ * @exception: the exception that was raised
71
+ * @host: the name of the host that made the request
72
+ * @backtrace: a sanitized version of the exception's backtrace
73
+ * @rails_root: a sanitized version of RAILS_ROOT
74
+ * @data: a hash of optional data values that were passed to the notifier
75
+ * @sections: the array of sections to include in the email
76
+
77
+ You can reorder the sections, or exclude sections completely, by altering the
78
+ ExceptionNotifier.sections variable. You can even add new sections that
79
+ describe application-specific data--just add the section's name to the list
80
+ (whereever you'd like), and define the corresponding partial. Then, if your
81
+ new section requires information that isn't available by default, make sure
82
+ it is made available to the email using the exception_data macro:
83
+
84
+ class ApplicationController < ActionController::Base
85
+ ...
86
+ protected
87
+ exception_data :additional_data
88
+
89
+ def additional_data
90
+ { :document => @document,
91
+ :person => @person }
92
+ end
93
+ ...
94
+ end
95
+
96
+ In the above case, @document and @person would be made available to the email
97
+ renderer, allowing your new section(s) to access and display them. See the
98
+ existing sections defined by the plugin for examples of how to write your own.
99
+
100
+ == Advanced Customization
101
+
102
+ By default, the email notifier will only notify on critical errors. For
103
+ ActiveRecord::RecordNotFound and ActionController::UnknownAction, it will
104
+ simply render the contents of your public/404.html file. Other exceptions
105
+ will render public/500.html and will send the email notification. If you want
106
+ to use different rules for the notification, you will need to implement your
107
+ own rescue_action_in_public method. You can look at the default implementation
108
+ in ExceptionNotifiable for an example of how to go about that.
109
+
110
+
111
+ Copyright (c) 2005 Jamis Buck, released under the MIT license
@@ -0,0 +1,99 @@
1
+ require 'ipaddr'
2
+
3
+ # Copyright (c) 2005 Jamis Buck
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ module ExceptionNotifiable
24
+ def self.included(target)
25
+ target.extend(ClassMethods)
26
+ end
27
+
28
+ module ClassMethods
29
+ def consider_local(*args)
30
+ local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) })
31
+ end
32
+
33
+ def local_addresses
34
+ addresses = read_inheritable_attribute(:local_addresses)
35
+ unless addresses
36
+ addresses = [IPAddr.new("127.0.0.1")]
37
+ write_inheritable_attribute(:local_addresses, addresses)
38
+ end
39
+ addresses
40
+ end
41
+
42
+ def exception_data(deliverer=self)
43
+ if deliverer == self
44
+ read_inheritable_attribute(:exception_data)
45
+ else
46
+ write_inheritable_attribute(:exception_data, deliverer)
47
+ end
48
+ end
49
+
50
+ def exceptions_to_treat_as_404
51
+ exceptions = [ActiveRecord::RecordNotFound,
52
+ ActionController::UnknownController,
53
+ ActionController::UnknownAction]
54
+ exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError)
55
+ exceptions
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def local_request?
62
+ remote = IPAddr.new(request.remote_ip)
63
+ !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
64
+ end
65
+
66
+ def render_404
67
+ respond_to do |type|
68
+ type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
69
+ type.all { render :nothing => true, :status => "404 Not Found" }
70
+ end
71
+ end
72
+
73
+ def render_500
74
+ respond_to do |type|
75
+ type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
76
+ type.all { render :nothing => true, :status => "500 Error" }
77
+ end
78
+ end
79
+
80
+ def rescue_action_in_public(exception)
81
+ case exception
82
+ when *self.class.exceptions_to_treat_as_404
83
+ render_404
84
+
85
+ else
86
+ render_500
87
+
88
+ deliverer = self.class.exception_data
89
+ data = case deliverer
90
+ when nil then {}
91
+ when Symbol then send(deliverer)
92
+ when Proc then deliverer.call(self)
93
+ end
94
+
95
+ ExceptionNotifier.deliver_exception_notification(exception, self,
96
+ request, data)
97
+ end
98
+ end
99
+ end