contingency-rails 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -13
- data/contingency-rails.gemspec +4 -5
- data/lib/contingency/rails/configuration.rb +62 -0
- data/lib/contingency/{adapters/rails → rails}/version.rb +1 -1
- data/lib/contingency/rails.rb +44 -0
- metadata +22 -8
- data/lib/contingency/adapters/rails/configuration.rb +0 -68
- data/lib/contingency/adapters/rails.rb +0 -45
- /data/lib/contingency/{adapters/rails → rails}/railtie.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2728293cf7d1fe106ad5a94e7f6875366b7bc68
|
4
|
+
data.tar.gz: 43f2b7ead9fda56a3b6a5e89aa3811e55b0b9984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e0a2a2ae80cc9acb42f31717067e651da56fbe8c5385e63126db75eed926ca91b96680b14c994cb2e1c4b06757e32e58909ec527cbc98c37dfb597028291ee
|
7
|
+
data.tar.gz: 06f2dc823c1bed2cab20528c555ab86dead18dd354cb598e0ab6cd4ee7759a76c1a88eee0a09bf0c2301756fa683d600820f62f2bb87619dd9fd9eceb1c4ee68
|
data/README.md
CHANGED
@@ -1,29 +1,78 @@
|
|
1
|
-
|
1
|
+
<a name='contingency-rails-readme'>
|
2
|
+
# Contingency-Rails
|
3
|
+
</a>
|
2
4
|
|
3
|
-
|
5
|
+
> "Freedom is the recognition of contingency."
|
4
6
|
|
7
|
+
> * *Richard M. Rorty*
|
8
|
+
|
9
|
+
Contingency-Rails provides [Contingency](https://github.com/christhekeele/contingency) integration for [Rails](http://rubyonrails.org/).
|
10
|
+
|
11
|
+
<a name='table-of-contents'>
|
12
|
+
## Table of Contents
|
13
|
+
</a>
|
14
|
+
|
15
|
+
* [Installation](#installation)
|
16
|
+
* [Configuration](#configuration)
|
17
|
+
* [Extra Routes](#extra-routes)
|
18
|
+
* [Error Codes](#error-codes)
|
19
|
+
* [Catch-all Routes](#catch-alls)
|
20
|
+
* [Contributing to Contingency-Rails](#contributing-to-contingency-rails)
|
21
|
+
|
22
|
+
<a name='installation'>
|
5
23
|
## Installation
|
24
|
+
</a>
|
6
25
|
|
7
26
|
Add this line to your application's Gemfile:
|
8
27
|
|
9
|
-
gem 'contingency-rails'
|
28
|
+
gem 'contingency-rails', '~> 3.0'
|
10
29
|
|
11
|
-
|
30
|
+
Then, execute:
|
12
31
|
|
13
32
|
$ bundle
|
14
33
|
|
15
|
-
|
34
|
+
Finally, add this to your `ApplicationController`:
|
35
|
+
|
36
|
+
include Contingency::Plan
|
37
|
+
|
38
|
+
<a name='configuration'>
|
39
|
+
## Configuration
|
40
|
+
</a>
|
41
|
+
|
42
|
+
Contingency-Rails uses the same configuration object as Contingency, but has different defaults. Run 'rake contingency:generate:rails:config' to get the example initializer. If you decide to skip this step, make sure you call `Contingency.configure` *somewhere* in your boot process, and that you have a view called `error` at `app/views/errors/`.
|
43
|
+
|
44
|
+
<a name='extra-routes)'>
|
45
|
+
## Extra Routes
|
46
|
+
</a>
|
47
|
+
|
48
|
+
Once you've configured your errors, you can get some additional features out of Contingency by adding a few routes to your `routes.rb`
|
49
|
+
|
50
|
+
<a name='error-codes)'>
|
51
|
+
### Error Codes
|
52
|
+
</a>
|
53
|
+
|
54
|
+
At the bottom of your routes, add this line:
|
55
|
+
|
56
|
+
match "/:code", to: 'application#error', as: :error, constraints: {code: /\d{3}/}
|
57
|
+
|
58
|
+
This controller action allows you to access your custom error pages directly. This means in development mode you won't have to change `config.consider_all_requests_local` to true and intentionally raise an error in one of your controllers just to see if your two lines of CSS improved the feel of your error page.
|
59
|
+
|
60
|
+
<a name='catch-alls)'>
|
61
|
+
### Catch-all Routes
|
62
|
+
</a>
|
16
63
|
|
17
|
-
|
64
|
+
At the **VERY** bottom of your routes, add this line:
|
18
65
|
|
19
|
-
|
66
|
+
match '/*invalid_url', to: 'application#routing_error'
|
20
67
|
|
21
|
-
|
68
|
+
This Rails-specific controller action enables Contingency to catch `ActionController::RoutingError` exceptions. Normally, invalid URLs in Rails are handled by Rack, so the Contingency Plan living in your controller can't rescue from it. Append this globbed route to the very end of your routes, and it can.
|
22
69
|
|
23
|
-
|
70
|
+
<a name='contributing-to-contingency-rails'>
|
71
|
+
## Contributing to Contingency
|
72
|
+
</a>
|
24
73
|
|
25
74
|
1. Fork it
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
75
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
1. Create new Pull Request
|
data/contingency-rails.gemspec
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'contingency/
|
4
|
+
require 'contingency/rails/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "contingency-rails"
|
8
8
|
spec.version = Contingency::Adapters::Rails::VERSION
|
9
9
|
spec.authors = ["Christopher Keele"]
|
10
10
|
spec.email = ["dev@chriskeele.com"]
|
11
|
-
spec.description = "
|
12
|
-
spec.summary = "Contingency-Rails
|
13
|
-
# spec.homepage = ""
|
11
|
+
spec.description = "Contingency integration for Rails."
|
12
|
+
spec.summary = "Contingency-Rails provides controller exception catching and routes to your custom error pages."
|
14
13
|
spec.license = "MIT"
|
15
14
|
|
16
15
|
spec.files = `git ls-files`.split($/)
|
@@ -18,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
|
20
|
+
spec.add_dependency "contingency", ">= 0.2.0"
|
22
21
|
spec.add_dependency "rails", "~> 3.0"
|
23
22
|
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Contingency
|
2
|
+
|
3
|
+
module Adapters
|
4
|
+
module Rails
|
5
|
+
class Configuration < Contingency::Configuration
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@errors = {
|
9
|
+
500.to_s => [ Exception ],
|
10
|
+
404.to_s => [
|
11
|
+
ActiveRecord::RecordNotFound,
|
12
|
+
ActionController::UnknownController,
|
13
|
+
AbstractController::ActionNotFound,
|
14
|
+
ActionController::RoutingError,
|
15
|
+
],
|
16
|
+
}
|
17
|
+
|
18
|
+
@error_messages = {
|
19
|
+
401.to_s => [
|
20
|
+
'Unauthorized',
|
21
|
+
'You should log in before you try that!'
|
22
|
+
],
|
23
|
+
403.to_s => [
|
24
|
+
'Forbidden',
|
25
|
+
'You don\'t have permission to do that.'
|
26
|
+
],
|
27
|
+
404.to_s => [
|
28
|
+
'Not Found',
|
29
|
+
'You may have mistyped the address or the page may have moved.'
|
30
|
+
],
|
31
|
+
405.to_s => [
|
32
|
+
'Method Not Allowed',
|
33
|
+
'You may be trying to access our API with an invalid request method.'
|
34
|
+
],
|
35
|
+
406.to_s => [
|
36
|
+
'Not Acceptable',
|
37
|
+
'You may be trying to access our API with invalid request headers.'
|
38
|
+
],
|
39
|
+
500.to_s => [
|
40
|
+
'Internal Server Error',
|
41
|
+
'It looks like something went wrong. Don\'t worry, we\'re on it!'
|
42
|
+
],
|
43
|
+
503.to_s => [
|
44
|
+
'Service Unavailable',
|
45
|
+
'We\'re down for maintainence right now.'
|
46
|
+
],
|
47
|
+
}
|
48
|
+
|
49
|
+
@error_layout = 'application'
|
50
|
+
@error_template = 'errors/error'
|
51
|
+
|
52
|
+
@unknown_error_message = ['Server Error', 'It looks like something went wrong.']
|
53
|
+
@failure_message = "Server Error: It looks like something went wrong."
|
54
|
+
|
55
|
+
@logger = ::Rails.logger
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'contingency'
|
2
|
+
|
3
|
+
module Contingency
|
4
|
+
|
5
|
+
module Adapters
|
6
|
+
module Rails
|
7
|
+
|
8
|
+
include Interface
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def catch_errors?
|
12
|
+
!::Rails.application.config.action_dispatch.show_exceptions or !::Rails.application.config.consider_all_requests_local
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_renderer(code)
|
21
|
+
render Contingency.configuration.error_template,
|
22
|
+
status: code,
|
23
|
+
layout: Contingency.configuration.error_layout
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_renderer(code)
|
27
|
+
render status: code, text: Contingency.configuration.failure_message
|
28
|
+
end
|
29
|
+
|
30
|
+
# Custom controller action.
|
31
|
+
# Raises traditional Rack-level Rails RoutingError at Application-level instead,
|
32
|
+
# so it `rescue_from` in Contingency's error handler can catch it instead of Rack's.
|
33
|
+
# Works in conjunction with a catchall route pointed at this controller action.
|
34
|
+
def routing_error
|
35
|
+
raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'contingency/rails/configuration'
|
43
|
+
require 'contingency/rails/railtie'
|
44
|
+
require "contingency/rails/version"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contingency-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Keele
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: contingency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +52,7 @@ dependencies:
|
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.3'
|
41
|
-
description:
|
55
|
+
description: Contingency integration for Rails.
|
42
56
|
email:
|
43
57
|
- dev@chriskeele.com
|
44
58
|
executables: []
|
@@ -51,10 +65,10 @@ files:
|
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
53
67
|
- contingency-rails.gemspec
|
54
|
-
- lib/contingency/
|
55
|
-
- lib/contingency/
|
56
|
-
- lib/contingency/
|
57
|
-
- lib/contingency/
|
68
|
+
- lib/contingency/rails.rb
|
69
|
+
- lib/contingency/rails/configuration.rb
|
70
|
+
- lib/contingency/rails/railtie.rb
|
71
|
+
- lib/contingency/rails/version.rb
|
58
72
|
homepage:
|
59
73
|
licenses:
|
60
74
|
- MIT
|
@@ -78,7 +92,7 @@ rubyforge_project:
|
|
78
92
|
rubygems_version: 2.0.0
|
79
93
|
signing_key:
|
80
94
|
specification_version: 4
|
81
|
-
summary: Contingency-Rails
|
82
|
-
|
95
|
+
summary: Contingency-Rails provides controller exception catching and routes to your
|
96
|
+
custom error pages.
|
83
97
|
test_files: []
|
84
98
|
has_rdoc:
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Contingency
|
2
|
-
|
3
|
-
module Adapters
|
4
|
-
module Rails
|
5
|
-
def default_configuration
|
6
|
-
|
7
|
-
config.error_layout = 'application'
|
8
|
-
config.error_template = 'errors/error'
|
9
|
-
|
10
|
-
###
|
11
|
-
# A hash of errors mapped to status codes.
|
12
|
-
# `ActiveSupport::Rescuable#rescue_from` will catch these
|
13
|
-
# and pass them to `Contingency::ErrorHandler`.
|
14
|
-
# Ensure that your general case exception comes first in the list,
|
15
|
-
# otherwise it will catch everything. Not sure why, I think it's
|
16
|
-
# something about `ActiveSupport::Rescuable#rescue_from`.
|
17
|
-
|
18
|
-
config.errors = {
|
19
|
-
500.to_s => [ Exception ],
|
20
|
-
404.to_s => [
|
21
|
-
ActiveRecord::RecordNotFound,
|
22
|
-
ActionController::UnknownController,
|
23
|
-
AbstractController::ActionNotFound,
|
24
|
-
ActionController::RoutingError,
|
25
|
-
],
|
26
|
-
}
|
27
|
-
|
28
|
-
###
|
29
|
-
# A hash of error reports mapped to status codes.
|
30
|
-
# This should be under I18N and L10N instead of here, really.
|
31
|
-
# Takes an array of an error message and a description.
|
32
|
-
#
|
33
|
-
config.error_messages = {
|
34
|
-
401.to_s => [
|
35
|
-
'Unauthorized',
|
36
|
-
'You should log in before you try that!'
|
37
|
-
],
|
38
|
-
403.to_s => [
|
39
|
-
'Forbidden',
|
40
|
-
'You don\'t have permission to do that.'
|
41
|
-
],
|
42
|
-
404.to_s => [
|
43
|
-
'Not Found',
|
44
|
-
'You may have mistyped the address or the page may have moved.'
|
45
|
-
],
|
46
|
-
405.to_s => [
|
47
|
-
'Method Not Allowed',
|
48
|
-
'You may be trying to access our API with an invalid request method.'
|
49
|
-
],
|
50
|
-
406.to_s => [
|
51
|
-
'Not Acceptable',
|
52
|
-
'You may be trying to access our API with invalid request headers.'
|
53
|
-
],
|
54
|
-
500.to_s => [
|
55
|
-
'Internal Server Error',
|
56
|
-
'It looks like something went wrong. Don\'t worry, we\'re on it!'
|
57
|
-
],
|
58
|
-
503.to_s => [
|
59
|
-
'Service Unavailable',
|
60
|
-
'We\'re down for maintainence right now.'
|
61
|
-
],
|
62
|
-
}
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# require 'contingency'
|
2
|
-
binding.pry
|
3
|
-
|
4
|
-
module Contingency
|
5
|
-
|
6
|
-
module Adapters
|
7
|
-
module Rails
|
8
|
-
binding.pry
|
9
|
-
|
10
|
-
extend ActiveSupport::Concern
|
11
|
-
include Interface
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def catch_errors?
|
15
|
-
!::Rails.application.config.action_dispatch.show_exceptions or !::Rails.application.config.consider_all_requests_local
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module InstanceMethods
|
20
|
-
def error_renderer(code)
|
21
|
-
render Contingency.configuration.error_template,
|
22
|
-
status: code,
|
23
|
-
layout: Contingency.configuration.error_layout
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_renderer(code)
|
27
|
-
render status: code, text: Contingency.configuration.failure_message
|
28
|
-
end
|
29
|
-
|
30
|
-
# Custom controller action.
|
31
|
-
# Raises traditional Rack-level Rails RoutingError at Application-level instead,
|
32
|
-
# so it `rescue_from` in Contingency's error handler can catch it instead of Rack's.
|
33
|
-
# Works in conjunction with a catchall route pointed at this controller action.
|
34
|
-
def routing_error
|
35
|
-
raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
require 'contingency/adapters/rails/configuration'
|
44
|
-
require 'contingency/adapters/rails/railtie'
|
45
|
-
require "contingency/adapters/rails/version"
|
File without changes
|