Module: ExceptionNotifierHelper

Defined in:
lib/exception_notifier_helper.rb

Constant Summary collapse

VIEW_PATH =
"views/exception_notifier"
APP_PATH =
"#{RAILS_ROOT}/app/#{VIEW_PATH}"
PARAM_FILTER_REPLACEMENT =
"[FILTERED]"
COMPAT_MODE =
defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION < '2' : false

Instance Method Summary collapse

Instance Method Details

#exclude_raw_post_parameters?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/exception_notifier_helper.rb', line 47

def exclude_raw_post_parameters?
  @controller && @controller.respond_to?(:filter_parameters)
end

#filter_sensitive_post_data_from_env(env_key, env_value) ⇒ Object



55
56
57
58
59
# File 'lib/exception_notifier_helper.rb', line 55

def filter_sensitive_post_data_from_env(env_key, env_value)
  return env_value unless exclude_raw_post_parameters?
  return PARAM_FILTER_REPLACEMENT if (env_key =~ /RAW_POST_DATA/i)
  return COMPAT_MODE ? @controller.filter_parameters({env_key => env_value}).values[0] : @controller.__send__(:filter_parameters, {env_key => env_value}).values[0]
end

#filter_sensitive_post_data_parameters(parameters) ⇒ Object



51
52
53
# File 'lib/exception_notifier_helper.rb', line 51

def filter_sensitive_post_data_parameters(parameters)
  exclude_raw_post_parameters? ? COMPAT_MODE ? @controller.filter_parameters(parameters) : @controller.__send__(:filter_parameters, parameters) : parameters
end

#inspect_model_object(model, locals = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/exception_notifier_helper.rb', line 29

def inspect_model_object(model, locals={})
  render_overridable(:inspect_model,
    :locals => { :inspect_model => model,
                 :show_instance_variables => true,
                 :show_attributes => true }.merge(locals))
end

#inspect_value(value) ⇒ Object



36
37
38
39
40
41
# File 'lib/exception_notifier_helper.rb', line 36

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

#object_to_yaml(object) ⇒ Object



43
44
45
# File 'lib/exception_notifier_helper.rb', line 43

def object_to_yaml(object)
  object.to_yaml.sub(/^---\s*/m, "")
end

#render_overridable(partial, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/exception_notifier_helper.rb', line 18

def render_overridable(partial, options={})
  if File.exist?(path = "#{APP_PATH}/_#{partial}.html.erb") ||
      File.exist?(path = "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.html.erb") ||
      File.exist?(path = "#{APP_PATH}/_#{partial}.rhtml") ||
      File.exist?(path = "#{APP_PATH}/_#{partial}.erb")
    render(options.merge(:file => path, :use_full_path => false))
  else
    ""
  end
end

#render_section(section) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/exception_notifier_helper.rb', line 9

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