wrangler 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -91,15 +91,22 @@ Here is the full set of configuration values for both classes, as well as their
91
91
  # match will NOT send notification emails (e.g. for filtering out crazy
92
92
  # browsers).
93
93
  # array of hashes, each with one key (http header string) and a value
94
- # (regexp to match in http header string)
94
+ # (regexp to match in http header string). this allows for more than one
95
+ # regexp to be specified for the same header if that's more convenient.
96
+ # any one pattern match will block notification.
97
+ # note that this looks in all request headers, including query params
98
+ # (e.g. form fields, url query params)
95
99
  :block_notify_on_request_headers => [],
96
100
  # configure whether to send emails synchronously or asynchronously
97
101
  # using delayed_job (these can be true even if delayed job is not
98
102
  # installed, in which case, will just send emails synchronously anyway)
99
- :delayed_job_for_controller_errors => false,
100
- :delayed_job_for_non_controller_errors => false,
103
+ :delayed_job_for_controller_errors => true,
104
+ :delayed_job_for_non_controller_errors => true,
101
105
  # mappings from exception classes to http status codes (see above)
102
106
  # add/remove from this list as desired in environment configuration
107
+ # note that the keys are String names of the classes, not the class
108
+ # constants themselves
109
+ # (e.g. "StandardError" => "500", and _NOT_ StandardError => "500")
103
110
  :error_class_status_codes => Wrangler::codes_for_exception_classes,
104
111
  # explicitly indicate which exceptions to send email notifications for
105
112
  :notify_exception_classes => %w(),
@@ -108,13 +115,21 @@ Here is the full set of configuration values for both classes, as well as their
108
115
  # where to look for app-specific error page templates (ones you create
109
116
  # yourself, for example...there are some defaults in this gem you can
110
117
  # use as well...and that are configured already by default)
111
- :error_template_dir => File.join(RAILS_ROOT, 'app', 'views', 'error'),
112
- # excplicit mappings from exception class to arbitrary error page
118
+ :error_template_dir => (defined?(RAILS_ROOT) ? File.join(RAILS_ROOT, 'app', 'views', 'error') : nil),
119
+ # explicit mappings from exception class to arbitrary error page
113
120
  # templates, different set for html and js responses (Wrangler determines
114
121
  # which to use automatically, so you can have an entry in both
115
122
  # hashes for the same error class)
123
+ # note that the keys are String names of the classes, not the class
124
+ # constants themselves
125
+ # (e.g. "StandardError" => "file", and _NOT_ StandardError => "file")
116
126
  :error_class_html_templates => {},
117
127
  :error_class_js_templates => {},
128
+ # you can specify options to pass to the render() call when rendering
129
+ # error page for errors. This is applied globally, so plan accordingly
130
+ # (one good option is to pass in :layout => 'my_layout' so your app
131
+ # layout gets applied to the error templates)
132
+ :render_error_options => {},
118
133
  # you can specify a fallback failsafe error template to render if
119
134
  # no appropriate template is found in the usual places (you shouldn't
120
135
  # rely on this, and error messages will be logged if this template is
@@ -130,8 +145,20 @@ Here is the full set of configuration values for both classes, as well as their
130
145
  # regexp-style
131
146
 
132
147
  # just DON'T change this! this is the error template of last resort!
148
+ # if you do change this, you really should have a good reason for it and
149
+ # really know what you're doing. really.
133
150
  :absolute_last_resort_default_error_template =>
134
- File.join(WRANGLER_ROOT,'rails','app','views','wrangler','500.html')
151
+ File.join(WRANGLER_ROOT,'rails','app','views','wrangler','500.html'),
152
+ # allows for inserting additional data/comments/status/environment into
153
+ # the notification emails. possibilities include fetching the release number,
154
+ # patch info, current state of different services....
155
+ # pass a proc instance that accepts a single
156
+ # argument, the request object (if any).
157
+ # (e.g. +Proc.new { |request| puts "request is: #{request}" }+, but don't
158
+ # do that, that would be redundant, silly and not secure).
159
+ # NOTE: +request+ can be nil (if background process, for example), so
160
+ # implement accordingly
161
+ :call_for_supplementary_info => nil
135
162
 
136
163
  #####################
137
164
  # ExceptionNotifier:
data/lib/wrangler.rb CHANGED
@@ -100,7 +100,7 @@ module Wrangler
100
100
 
101
101
  # if that didn't work, fall back on configured app-specific default
102
102
  if file_path.blank? || !File.exists?(file_path)
103
- file_path = config[:default_error_template]
103
+ file_path = Wrangler::Exception_handler.config[:default_error_template]
104
104
 
105
105
  log_error(["Could not find an error template in the usual places " +
106
106
  "for exception #{exception.class}, status code " +
@@ -110,7 +110,7 @@ module Wrangler
110
110
 
111
111
  # as a last resort, just render the gem's 500 error
112
112
  if file_path.blank? || !File.exists?(file_path)
113
- file_path = config[:absolute_last_resort_default_error_template]
113
+ file_path = Wrangler::ExceptionHandler.config[:absolute_last_resort_default_error_template]
114
114
 
115
115
  log_error("Still no template found. Using gem default of " +
116
116
  file_path)
@@ -118,8 +118,13 @@ module Wrangler
118
118
 
119
119
  log_error("Will render error template: '#{file_path}'")
120
120
 
121
- render :file => file_path,
122
- :status => status_code
121
+ options = { :file => file_path, :status => status_code }
122
+
123
+ unless Wrangler::ExceptionHandler.config[:render_error_options].blank?
124
+ options.merge! Wrangler::ExceptionHandler.config[:render_error_options]
125
+ end
126
+
127
+ render options
123
128
  end
124
129
 
125
130
 
@@ -148,21 +153,20 @@ module Wrangler
148
153
  case request.format
149
154
  when /html/
150
155
  response_format = 'html'
151
- template_mappings = config[:error_class_html_templates]
156
+ template_mappings = Wrangler::ExceptionHandler.config[:error_class_html_templates]
152
157
  when /js/
153
158
  response_format = 'js'
154
- template_mappings = config[:error_class_js_templates]
159
+ template_mappings = Wrangler::ExceptionHandler.config[:error_class_js_templates]
155
160
  when /xml/
156
161
  'xml'
157
162
  end
158
163
  format_extension_pattern = ".#{response_format || ''}*"
159
164
 
160
165
  if template_mappings
161
-
162
166
  # search for direct mapping from exception name to error template
163
167
 
164
- if template_mappings[exception_class]
165
- error_file = template_mappings[exception_class]
168
+ if template_mappings[exception_class.name]
169
+ error_file = template_mappings[exception_class.name]
166
170
 
167
171
  return error_file if File.exists?(error_file)
168
172
 
@@ -172,13 +176,12 @@ module Wrangler
172
176
  end
173
177
 
174
178
  # search for mapping from an ancestor class to error template
175
-
176
179
  ancestor_class =
177
180
  Wrangler::class_has_ancestor?(exception_class.superclass,
178
- template_mappings)
181
+ template_mappings.keys)
179
182
 
180
183
  if ancestor_class
181
- error_file = template_mappings[ancestor_class]
184
+ error_file = template_mappings[ancestor_class.name]
182
185
 
183
186
  return error_file if File.exists?(error_file)
184
187
 
@@ -191,7 +194,7 @@ module Wrangler
191
194
 
192
195
  # search for a file named after the exception in one of the search dirs
193
196
 
194
- search_paths = [ config[:error_template_dir],
197
+ search_paths = [ Wrangler::ExceptionHandler::config[:error_template_dir],
195
198
  File.join(RAILS_ROOT, 'public'),
196
199
  File.join(WRANGLER_ROOT, 'rails', 'app', 'views', 'wrangler')
197
200
  ]
@@ -7,28 +7,28 @@ module Wrangler
7
7
  def self.codes_for_exception_classes
8
8
  classes = {
9
9
  # These are standard errors in rails / ruby
10
- NameError => "503",
11
- TypeError => "503",
12
- RuntimeError => "500",
13
- ArgumentError => "500",
10
+ NameError.name => "503",
11
+ TypeError.name => "503",
12
+ RuntimeError.name => "500",
13
+ ArgumentError.name => "500",
14
14
  # the default mapping for an unrecognized exception class
15
15
  :default => "500"
16
16
  }
17
17
 
18
18
  # from exception_notification gem:
19
19
  # Highly dependent on the verison of rails, so we're very protective about these'
20
- classes.merge!({ ActionView::TemplateError => "500"}) if defined?(ActionView) && ActionView.const_defined?(:TemplateError)
21
- classes.merge!({ ActiveRecord::RecordNotFound => "400" }) if defined?(ActiveRecord) && ActiveRecord.const_defined?(:RecordNotFound)
22
- classes.merge!({ ActiveResource::ResourceNotFound => "404" }) if defined?(ActiveResource) && ActiveResource.const_defined?(:ResourceNotFound)
20
+ classes.merge!({ ActionView::TemplateError.name => "500"}) if defined?(ActionView) && ActionView.const_defined?(:TemplateError)
21
+ classes.merge!({ ActiveRecord::RecordNotFound.name => "400" }) if defined?(ActiveRecord) && ActiveRecord.const_defined?(:RecordNotFound)
22
+ classes.merge!({ ActiveResource::ResourceNotFound.name => "404" }) if defined?(ActiveResource) && ActiveResource.const_defined?(:ResourceNotFound)
23
23
 
24
24
  # from exception_notification gem:
25
25
  if defined?(ActionController)
26
- classes.merge!({ ActionController::UnknownController => "404" }) if ActionController.const_defined?(:UnknownController)
27
- classes.merge!({ ActionController::MissingTemplate => "404" }) if ActionController.const_defined?(:MissingTemplate)
28
- classes.merge!({ ActionController::MethodNotAllowed => "405" }) if ActionController.const_defined?(:MethodNotAllowed)
29
- classes.merge!({ ActionController::UnknownAction => "501" }) if ActionController.const_defined?(:UnknownAction)
30
- classes.merge!({ ActionController::RoutingError => "404" }) if ActionController.const_defined?(:RoutingError)
31
- classes.merge!({ ActionController::InvalidAuthenticityToken => "405" }) if ActionController.const_defined?(:InvalidAuthenticityToken)
26
+ classes.merge!({ ActionController::UnknownController.name => "404" }) if ActionController.const_defined?(:UnknownController)
27
+ classes.merge!({ ActionController::MissingTemplate.name => "404" }) if ActionController.const_defined?(:MissingTemplate)
28
+ classes.merge!({ ActionController::MethodNotAllowed.name => "405" }) if ActionController.const_defined?(:MethodNotAllowed)
29
+ classes.merge!({ ActionController::UnknownAction.name => "501" }) if ActionController.const_defined?(:UnknownAction)
30
+ classes.merge!({ ActionController::RoutingError.name => "404" }) if ActionController.const_defined?(:RoutingError)
31
+ classes.merge!({ ActionController::InvalidAuthenticityToken.name => "405" }) if ActionController.const_defined?(:InvalidAuthenticityToken)
32
32
  end
33
33
 
34
34
  return classes
@@ -72,6 +72,9 @@ module Wrangler
72
72
  :delayed_job_for_non_controller_errors => true,
73
73
  # mappings from exception classes to http status codes (see above)
74
74
  # add/remove from this list as desired in environment configuration
75
+ # note that the keys are String names of the classes, not the class
76
+ # constants themselves
77
+ # (e.g. "StandardError" => "500", and _NOT_ StandardError => "500")
75
78
  :error_class_status_codes => Wrangler::codes_for_exception_classes,
76
79
  # explicitly indicate which exceptions to send email notifications for
77
80
  :notify_exception_classes => %w(),
@@ -81,12 +84,20 @@ module Wrangler
81
84
  # yourself, for example...there are some defaults in this gem you can
82
85
  # use as well...and that are configured already by default)
83
86
  :error_template_dir => (defined?(RAILS_ROOT) ? File.join(RAILS_ROOT, 'app', 'views', 'error') : nil),
84
- # excplicit mappings from exception class to arbitrary error page
87
+ # explicit mappings from exception class to arbitrary error page
85
88
  # templates, different set for html and js responses (Wrangler determines
86
89
  # which to use automatically, so you can have an entry in both
87
90
  # hashes for the same error class)
91
+ # note that the keys are String names of the classes, not the class
92
+ # constants themselves
93
+ # (e.g. "StandardError" => "file", and _NOT_ StandardError => "file")
88
94
  :error_class_html_templates => {},
89
95
  :error_class_js_templates => {},
96
+ # you can specify options to pass to the render() call when rendering
97
+ # error page for errors. This is applied globally, so plan accordingly
98
+ # (one good option is to pass in :layout => 'my_layout' so your app
99
+ # layout gets applied to the error templates)
100
+ :render_error_options => {},
90
101
  # you can specify a fallback failsafe error template to render if
91
102
  # no appropriate template is found in the usual places (you shouldn't
92
103
  # rely on this, and error messages will be logged if this template is
@@ -106,7 +117,6 @@ module Wrangler
106
117
  # really know what you're doing. really.
107
118
  :absolute_last_resort_default_error_template =>
108
119
  File.join(WRANGLER_ROOT,'rails','app','views','wrangler','500.html'),
109
-
110
120
  # allows for inserting additional data/comments/status/environment into
111
121
  # the notification emails. possibilities include fetching the release number,
112
122
  # patch info, current state of different services....
@@ -173,7 +183,7 @@ module Wrangler
173
183
  if exception.respond_to?(:status_code)
174
184
  return exception.status_code
175
185
  else
176
- return config[:error_class_status_codes][exception.class] ||
186
+ return config[:error_class_status_codes][exception.class.name] ||
177
187
  config[:error_class_status_codes][:default]
178
188
  end
179
189
  end
@@ -23,15 +23,19 @@ module Wrangler
23
23
  # classes as an ancestor
24
24
  # - other_klasses: a Class, an Array (or any other container that responds
25
25
  # to include?() ) of Classes
26
+ #
26
27
  #-----------------------------------------------------------------------------
27
28
  def class_has_ancestor?(klass, other_klasses)
28
29
  return nil if !klass.is_a?(Class)
29
30
 
30
- other_klasses = [other_klasses] if other_klasses.is_a?(Class)
31
+ other_klasses = [other_klasses] unless other_klasses.is_a?(Array)
32
+ if other_klasses.first.is_a?(Class)
33
+ other_klasses.map! { |k| k.name }
34
+ end
31
35
 
32
36
  current_klass = klass
33
37
  while current_klass
34
- return current_klass if other_klasses.include?(current_klass)
38
+ return current_klass if other_klasses.include?(current_klass.name)
35
39
  current_klass = current_klass.superclass
36
40
  end
37
41
 
data/wrangler.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wrangler}
8
- s.version = "0.1.21"
8
+ s.version = "0.1.22"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Percival"]
12
- s.date = %q{2010-05-18}
12
+ s.date = %q{2010-06-15}
13
13
  s.description = %q{A gem for handling exceptions thrown inside your Rails app. If you include the
14
14
  gem in your application controller, wrangler will render the error pages you
15
15
  configure for each exception or HTTP error code. It will also handle notifying
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrangler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Percival
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-18 00:00:00 -07:00
12
+ date: 2010-06-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency