Class: HydraulicBrake::Notice
- Inherits:
-
Object
- Object
- HydraulicBrake::Notice
- Defined in:
- lib/hydraulic_brake/notice.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
The action (if any) that was called in this request.
-
#api_key ⇒ Object
readonly
The API key for the project to which this notice should be sent.
-
#backtrace ⇒ Object
readonly
The backtrace from the given exception or hash.
-
#backtrace_filters ⇒ Object
readonly
See Configuration#backtrace_filters.
-
#cgi_data ⇒ Object
readonly
CGI variables such as HTTP_METHOD.
-
#component ⇒ Object
(also: #controller)
readonly
The component (if any) which was used in this request (usually the controller).
-
#environment_name ⇒ Object
readonly
The name of the server environment (such as “production”).
-
#error_class ⇒ Object
readonly
The name of the class of error (such as RuntimeError).
-
#error_message ⇒ Object
readonly
The message from the exception, or a general description of the error.
-
#exception ⇒ Object
readonly
The exception that caused this notice, if any.
-
#hostname ⇒ Object
readonly
The host name where this error occurred (if any).
-
#notifier_name ⇒ Object
readonly
The name of the notifier library sending this notice, such as “HydraulicBrake Notifier”.
-
#notifier_url ⇒ Object
readonly
A URL for more information about the notifier library sending this notice.
-
#notifier_version ⇒ Object
readonly
The version number of the notifier library sending this notice, such as “2.1.3”.
-
#parameters ⇒ Object
(also: #params)
readonly
A hash of parameters from the query string or post body.
-
#params_filters ⇒ Object
readonly
See Configuration#params_filters.
-
#project_root ⇒ Object
readonly
The path to the project that caused the error (usually Rails.root).
-
#session_data ⇒ Object
readonly
A hash of session data from the request.
-
#url ⇒ Object
readonly
The URL at which the error occurred (if any).
-
#user ⇒ Object
readonly
Details about the user who experienced the error.
Class Method Summary collapse
- .attr_reader_with_tracking(*names) ⇒ Object (also: attr_reader)
- .attr_readers ⇒ Object
Instance Method Summary collapse
-
#[](method) ⇒ Object
Allows properties to be accessed using a hash-like syntax.
-
#initialize(args) ⇒ Notice
constructor
A new instance of Notice.
-
#to_xml ⇒ Object
Converts the given notice to XML.
Constructor Details
#initialize(args) ⇒ Notice
Returns a new instance of Notice.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/hydraulic_brake/notice.rb', line 97 def initialize(args) self.args = args self.exception = args[:exception] self.api_key = args[:api_key] self.project_root = args[:project_root] self.url = args[:url] self.notifier_name = args[:notifier_name] self.notifier_version = args[:notifier_version] self.notifier_url = args[:notifier_url] self.backtrace_filters = args[:backtrace_filters] || [] self.params_filters = args[:params_filters] || [] self.parameters = args[:parameters] || {} self.component = args[:component] || args[:controller] || nil self.action = args[:action] || nil self.environment_name = args[:environment_name] self.cgi_data = args[:cgi_data] || {} self.backtrace = Backtrace.parse(exception_attribute(:backtrace, caller), :filters => self.backtrace_filters) self.error_class = exception_attribute(:error_class) {|exception| exception.class.name } self. = exception_attribute(:error_message, 'Notification') do |exception| "#{exception.class.name}: #{args[:error_message] || exception.}" end self.session_data = args[:session_data] || {} self.hostname = local_hostname self.user = args[:user] || {} clean_params end |
Instance Attribute Details
#action ⇒ Object
The action (if any) that was called in this request
58 59 60 |
# File 'lib/hydraulic_brake/notice.rb', line 58 def action @action end |
#api_key ⇒ Object
The API key for the project to which this notice should be sent
26 27 28 |
# File 'lib/hydraulic_brake/notice.rb', line 26 def api_key @api_key end |
#backtrace ⇒ Object
The backtrace from the given exception or hash.
29 30 31 |
# File 'lib/hydraulic_brake/notice.rb', line 29 def backtrace @backtrace end |
#backtrace_filters ⇒ Object
See Configuration#backtrace_filters
44 45 46 |
# File 'lib/hydraulic_brake/notice.rb', line 44 def backtrace_filters @backtrace_filters end |
#cgi_data ⇒ Object
CGI variables such as HTTP_METHOD
38 39 40 |
# File 'lib/hydraulic_brake/notice.rb', line 38 def cgi_data @cgi_data end |
#component ⇒ Object Also known as: controller
The component (if any) which was used in this request (usually the controller)
54 55 56 |
# File 'lib/hydraulic_brake/notice.rb', line 54 def component @component end |
#environment_name ⇒ Object
The name of the server environment (such as “production”)
35 36 37 |
# File 'lib/hydraulic_brake/notice.rb', line 35 def environment_name @environment_name end |
#error_class ⇒ Object
The name of the class of error (such as RuntimeError)
32 33 34 |
# File 'lib/hydraulic_brake/notice.rb', line 32 def error_class @error_class end |
#error_message ⇒ Object
The message from the exception, or a general description of the error
41 42 43 |
# File 'lib/hydraulic_brake/notice.rb', line 41 def @error_message end |
#exception ⇒ Object
The exception that caused this notice, if any
23 24 25 |
# File 'lib/hydraulic_brake/notice.rb', line 23 def exception @exception end |
#hostname ⇒ Object
The host name where this error occurred (if any)
79 80 81 |
# File 'lib/hydraulic_brake/notice.rb', line 79 def hostname @hostname end |
#notifier_name ⇒ Object
The name of the notifier library sending this notice, such as “HydraulicBrake Notifier”
70 71 72 |
# File 'lib/hydraulic_brake/notice.rb', line 70 def notifier_name @notifier_name end |
#notifier_url ⇒ Object
A URL for more information about the notifier library sending this notice
76 77 78 |
# File 'lib/hydraulic_brake/notice.rb', line 76 def notifier_url @notifier_url end |
#notifier_version ⇒ Object
The version number of the notifier library sending this notice, such as “2.1.3”
73 74 75 |
# File 'lib/hydraulic_brake/notice.rb', line 73 def notifier_version @notifier_version end |
#parameters ⇒ Object Also known as: params
A hash of parameters from the query string or post body.
50 51 52 |
# File 'lib/hydraulic_brake/notice.rb', line 50 def parameters @parameters end |
#params_filters ⇒ Object
See Configuration#params_filters
47 48 49 |
# File 'lib/hydraulic_brake/notice.rb', line 47 def params_filters @params_filters end |
#project_root ⇒ Object
The path to the project that caused the error (usually Rails.root)
64 65 66 |
# File 'lib/hydraulic_brake/notice.rb', line 64 def project_root @project_root end |
#session_data ⇒ Object
A hash of session data from the request
61 62 63 |
# File 'lib/hydraulic_brake/notice.rb', line 61 def session_data @session_data end |
#url ⇒ Object
The URL at which the error occurred (if any)
67 68 69 |
# File 'lib/hydraulic_brake/notice.rb', line 67 def url @url end |
#user ⇒ Object
Details about the user who experienced the error
82 83 84 |
# File 'lib/hydraulic_brake/notice.rb', line 82 def user @user end |
Class Method Details
.attr_reader_with_tracking(*names) ⇒ Object Also known as: attr_reader
8 9 10 11 |
# File 'lib/hydraulic_brake/notice.rb', line 8 def attr_reader_with_tracking(*names) attr_readers.concat(names) attr_reader_without_tracking(*names) end |
.attr_readers ⇒ Object
17 18 19 |
# File 'lib/hydraulic_brake/notice.rb', line 17 def attr_readers @attr_readers ||= [] end |
Instance Method Details
#[](method) ⇒ Object
Allows properties to be accessed using a hash-like syntax
198 199 200 201 202 203 204 205 |
# File 'lib/hydraulic_brake/notice.rb', line 198 def [](method) case method when :request self else send(method) end end |
#to_xml ⇒ Object
Converts the given notice to XML
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/hydraulic_brake/notice.rb', line 130 def to_xml builder = Builder::XmlMarkup.new builder.instruct! xml = builder.notice(:version => HydraulicBrake::API_VERSION) do |notice| notice.tag!("api-key", api_key) notice.notifier do |notifier| notifier.name(notifier_name) notifier.version(notifier_version) notifier.url(notifier_url) end notice.error do |error| error.tag!('class', error_class) error.() error.backtrace do |backtrace| self.backtrace.lines.each do |line| backtrace.line(:number => line.number, :file => line.file, :method => line.method) end end end if request_present? notice.request do |request| request.url(url) request.component(controller) request.action(action) unless parameters.nil? || parameters.empty? request.params do |params| xml_vars_for(params, parameters) end end unless session_data.empty? request.session do |session| xml_vars_for(session, session_data) end end unless cgi_data.nil? || cgi_data.empty? request.tag!("cgi-data") do |cgi_datum| xml_vars_for(cgi_datum, cgi_data) end end end end notice.tag!("server-environment") do |env| env.tag!("project-root", project_root) env.tag!("environment-name", environment_name) env.tag!("hostname", hostname) end unless user.empty? notice.tag!("current-user") do |u| u.tag!("id",user[:id]) u.tag!("name",user[:name]) u.tag!("email",user[:email]) u.tag!("username",user[:username]) end end end xml.to_s end |