Module: ExceptionNotification::NotifierHelper

Defined in:
lib/exception_notification/notifier_helper.rb

Overview

Copyright © 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.

Constant Summary collapse

PARAM_FILTER_REPLACEMENT =
"[FILTERED]"

Instance Method Summary collapse

Instance Method Details

#exclude_raw_post_parameters?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/exception_notification/notifier_helper.rb', line 52

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

#filter_sensitive_post_data_from_env(env_key, env_value) ⇒ Object



60
61
62
63
64
# File 'lib/exception_notification/notifier_helper.rb', line 60

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 @controller.__send__(:filter_parameters, {env_key => env_value}).values[0]
end

#filter_sensitive_post_data_parameters(parameters) ⇒ Object



56
57
58
# File 'lib/exception_notification/notifier_helper.rb', line 56

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

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



34
35
36
37
38
39
# File 'lib/exception_notification/notifier_helper.rb', line 34

def inspect_model_object(model, locals={})
  render('exception_notifier/inspect_model',
    :locals => { :inspect_model => model,
                 :show_instance_variables => true,
                 :show_attributes => true }.merge(locals))
end

#inspect_value(value) ⇒ Object



41
42
43
44
45
46
# File 'lib/exception_notification/notifier_helper.rb', line 41

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



48
49
50
# File 'lib/exception_notification/notifier_helper.rb', line 48

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

#render_section(section) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/exception_notification/notifier_helper.rb', line 26

def render_section(section)
  summary = render("exception_notifier/#{section}").strip
  unless summary.blank?
    title = render("exception_notifier/title", :title => section).strip
    "#{title}\n\n#{summary.gsub(/^/, "  ")}\n\n"
  end
end