0
+# Copyright (c) 2005 Jamis Buck
0
+# Permission is hereby granted, free of charge, to any person obtaining
0
+# a copy of this software and associated documentation files (the
0
+# "Software"), to deal in the Software without restriction, including
0
+# without limitation the rights to use, copy, modify, merge, publish,
0
+# distribute, sublicense, and/or sell copies of the Software, and to
0
+# permit persons to whom the Software is furnished to do so, subject to
0
+# the following conditions:
0
+# The above copyright notice and this permission notice shall be
0
+# included in all copies or substantial portions of the Software.
0
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
+module ExceptionLoggable
0
+ def self.included(target)
0
+ target.extend(ClassMethods)
0
+ def consider_local(*args)
0
+ local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) })
0
+ addresses = read_inheritable_attribute(:local_addresses)
0
+ addresses = [IPAddr.new("127.0.0.1")]
0
+ write_inheritable_attribute(:local_addresses, addresses)
0
+ def exception_data(deliverer=self)
0
+ read_inheritable_attribute(:exception_data)
0
+ write_inheritable_attribute(:exception_data, deliverer)
0
+ remote = IPAddr.new(request.remote_ip)
0
+ !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
0
+ type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
0
+ type.all { render :nothing => true, :status => "404 Not Found" }
0
+ type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
0
+ type.all { render :nothing => true, :status => "500 Error" }
0
+ def rescue_action_in_public(exception)
0
+ when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
0
+ deliverer = self.class.exception_data
0
+ when Symbol then send(deliverer)
0
+ when Proc then deliverer.call(self)
0
+ LoggedException.create_from_exception(self, exception)