Skip to content

Commit

Permalink
Make the notifier non-reloadable, so it is stable in development. Mak…
Browse files Browse the repository at this point in the history
…e the inspect-model helper more configurable. Show the current pid and server in the environment section.
  • Loading branch information
jamis committed Feb 10, 2006
1 parent f1d0ce1 commit 047568e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/exception_notifier.rb
Expand Up @@ -33,6 +33,8 @@ class ExceptionNotifier < ActionMailer::Base
@@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}"

Expand Down
17 changes: 11 additions & 6 deletions lib/exception_notifier_helper.rb
Expand Up @@ -25,24 +25,29 @@ module ExceptionNotifierHelper
APP_PATH = "#{RAILS_ROOT}/app/#{VIEW_PATH}"

def render_section(section)
summary = render_overridable(section).strip
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?("#{APP_PATH}/_#{partial}.rhtml")
render(options.merge(:file => "#{APP_PATH}/_#{partial}.rhtml", :use_full_path => false))
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
render(options.merge(:file => "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.rhtml", :use_full_path => false))
""
end
end

def inspect_model_object(model)
render_overridable(:inspect_model, :locals => { :inspect_model => model })
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)
Expand Down
3 changes: 3 additions & 0 deletions views/exception_notifier/_environment.rhtml
Expand Up @@ -2,3 +2,6 @@
<% @request.env.keys.sort.each do |key| -%>
* <%= "%*-s: %s" % [max.length, key, @request.env[key].to_s.strip] %>
<% end -%>

* Process: <%= $$ %>
* Server : <%= `hostname -s`.chomp %>
4 changes: 4 additions & 0 deletions views/exception_notifier/_inspect_model.rhtml
@@ -1,12 +1,16 @@
<% if show_attributes -%>
[attributes]
<% attrs = inspect_model.attributes -%>
<% max = attrs.keys.max { |a,b| a.length <=> b.length } -%>
<% attrs.keys.sort.each do |attr| -%>
* <%= "%*-s: %s" % [max.length, attr, object_to_yaml(attrs[attr]).gsub(/\n/, "\n ")] %>
<% end -%>
<% end -%>
<% if show_instance_variables -%>
[instance variables]
<% inspect_model.instance_variables.sort.each do |variable| -%>
<%- next if variable == "@attributes" -%>
* <%= variable %>: <%= inspect_value(inspect_model.instance_variable_get(variable)) %>
<% end -%>
<% end -%>

0 comments on commit 047568e

Please sign in to comment.