diff options
Diffstat (limited to 'vendor/plugins/exception_notification/lib/exception_notifiable.rb')
| -rw-r--r-- | vendor/plugins/exception_notification/lib/exception_notifiable.rb | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/vendor/plugins/exception_notification/lib/exception_notifiable.rb b/vendor/plugins/exception_notification/lib/exception_notifiable.rb deleted file mode 100644 index d5e28fc..0000000 --- a/vendor/plugins/exception_notification/lib/exception_notifiable.rb +++ /dev/null | |||
| @@ -1,99 +0,0 @@ | |||
| 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 | ||
