Initial commit of foodsoft 2

This commit is contained in:
Benjamin Meichsner 2009-01-06 11:49:19 +01:00
commit 5b9a7e05df
657 changed files with 70444 additions and 0 deletions

View file

@ -0,0 +1,99 @@
require 'ipaddr'
# Copyright (c) 2005 Jamis Buck
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# 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
def self.included(target)
target.extend(ClassMethods)
end
module ClassMethods
def consider_local(*args)
local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) })
end
def local_addresses
addresses = read_inheritable_attribute(:local_addresses)
unless addresses
addresses = [IPAddr.new("127.0.0.1")]
write_inheritable_attribute(:local_addresses, addresses)
end
addresses
end
def exception_data(deliverer=self)
if deliverer == self
read_inheritable_attribute(:exception_data)
else
write_inheritable_attribute(:exception_data, deliverer)
end
end
def exceptions_to_treat_as_404
exceptions = [ActiveRecord::RecordNotFound,
ActionController::UnknownController,
ActionController::UnknownAction]
exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError)
exceptions
end
end
private
def local_request?
remote = IPAddr.new(request.remote_ip)
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end
def render_404
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
type.all { render :nothing => true, :status => "404 Not Found" }
end
end
def render_500
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
type.all { render :nothing => true, :status => "500 Error" }
end
end
def rescue_action_in_public(exception)
case exception
when *self.class.exceptions_to_treat_as_404
render_404
else
render_500
deliverer = self.class.exception_data
data = case deliverer
when nil then {}
when Symbol then send(deliverer)
when Proc then deliverer.call(self)
end
ExceptionNotifier.deliver_exception_notification(exception, self,
request, data)
end
end
end

View file

@ -0,0 +1,67 @@
require 'pathname'
# Copyright (c) 2005 Jamis Buck
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# 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
@@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
cattr_accessor :sender_address
@@exception_recipients = []
cattr_accessor :exception_recipients
@@email_prefix = "[ERROR] "
cattr_accessor :email_prefix
@@sections = %w(request session environment backtrace)
cattr_accessor :sections
def self.reloadable?; false; end
def exception_notification(exception, controller, request, data={})
subject "#{email_prefix}#{controller.controller_name}##{controller.action_name} (#{exception.class}) #{exception.message.inspect}"
recipients exception_recipients
from sender_address
body data.merge({ :controller => controller, :request => request,
:exception => exception, :host => request.env["HTTP_HOST"],
:backtrace => sanitize_backtrace(exception.backtrace),
:rails_root => rails_root, :data => data,
:sections => sections })
end
def template_root
"#{File.dirname(__FILE__)}/../views"
end
private
def sanitize_backtrace(trace)
re = Regexp.new(/^#{Regexp.escape(rails_root)}/)
trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
end
def rails_root
return @rails_root if @rails_root
@rails_root = Pathname.new(RAILS_ROOT).cleanpath.to_s
end
end

View file

@ -0,0 +1,77 @@
require 'pp'
# Copyright (c) 2005 Jamis Buck
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# 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
VIEW_PATH = "views/exception_notifier"
APP_PATH = "#{RAILS_ROOT}/app/#{VIEW_PATH}"
PARAM_FILTER_REPLACEMENT = "[FILTERED]"
def render_section(section)
RAILS_DEFAULT_LOGGER.info("rendering section #{section.inspect}")
summary = render_overridable(section).strip
unless summary.blank?
title = render_overridable(:title, :locals => { :title => section }).strip
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
end
end
def render_overridable(partial, options={})
if File.exist?(path = "#{APP_PATH}/_#{partial}.rhtml")
render(options.merge(:file => path, :use_full_path => false))
elsif File.exist?(path = "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.rhtml")
render(options.merge(:file => path, :use_full_path => false))
else
""
end
end
def inspect_model_object(model, locals={})
render_overridable(:inspect_model,
:locals => { :inspect_model => model,
:show_instance_variables => true,
:show_attributes => true }.merge(locals))
end
def inspect_value(value)
len = 512
result = object_to_yaml(value).gsub(/\n/, "\n ").strip
result = result[0,len] + "... (#{result.length-len} bytes more)" if result.length > len+20
result
end
def object_to_yaml(object)
object.to_yaml.sub(/^---\s*/m, "")
end
def exclude_raw_post_parameters?
@controller && @controller.respond_to?(:filter_parameters)
end
def filter_sensitive_post_data_parameters(parameters)
exclude_raw_post_parameters? ? @controller.filter_parameters(parameters) : parameters
end
def filter_sensitive_post_data_from_env(env_key, env_value)
return env_value unless exclude_raw_post_parameters?
(env_key =~ /RAW_POST_DATA/i) ? PARAM_FILTER_REPLACEMENT : env_value
end
end