contingency 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -67
- data/lib/contingency/adapters/interface.rb +22 -30
- data/lib/contingency/plan.rb +5 -7
- data/lib/contingency/version.rb +1 -1
- data/lib/contingency.rb +3 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9134c71586b5d7aac0b9727f60bb93c42bbc7dd
|
4
|
+
data.tar.gz: 4997bbb2c4aa49e210def0d56b05501b8ad9407d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5c44af5d7d25603f7e3ba1352f6feb1e83abefe3b5af02c0271c5aa3e19bda3e716689404758d91b4d305e18d6e2849321546b59a4bd8504837659771be7c4
|
7
|
+
data.tar.gz: f9ede3175ea4026ecb8614b85f79778f7428b381ded5c13d8990372b840e9b686ac9789b12a39c9989ce2b82bc0e538469dd549909dec7cfdca242c48e1540d5
|
data/README.md
CHANGED
@@ -6,15 +6,13 @@
|
|
6
6
|
|
7
7
|
> * *Richard M. Rorty*
|
8
8
|
|
9
|
-
Contingency is the custom error page controller you've implemented in every project you've ever written. It's
|
9
|
+
Contingency is the custom error page controller you've implemented in every project you've ever written. It's designed to be framework-agnostic and has [many integrations](#supported-integrations) to make using it as easy as calling a config block.
|
10
10
|
|
11
|
-
So
|
11
|
+
So why implement it yourself again?
|
12
12
|
|
13
13
|
It's quick to get started, gives you full customization over Exception coverage, gives you full control over rendering your own error page, and has a contingency plan itself in the event that your custom error views trigger an Exception.
|
14
14
|
|
15
|
-
It's also very lightweight: the core functionality (the module in `contingency/plan.rb`) is less than 50 lines; and only adds 3 integration methods, 2 helper methods, and 1 controller action method to your controller. Everything but the controller method is private.
|
16
|
-
|
17
|
-
Experience true freedom, and make yourself a Contingency Plan.
|
15
|
+
It's also very lightweight: the core functionality (the module in `contingency/plan.rb`) is less than 50 lines; and only adds 3 integration methods, 2 helper methods, and 1 controller action method to your controller. Everything but the controller method is private.
|
18
16
|
|
19
17
|
<a name='table-of-contents'>
|
20
18
|
## Table of Contents
|
@@ -24,10 +22,10 @@ Experience true freedom, and make yourself a Contingency Plan.
|
|
24
22
|
* [Configuration](#configuration)
|
25
23
|
* [Supported Integrations](#supported-integrations)
|
26
24
|
* [Rails](#rails-integration)
|
27
|
-
* [
|
28
|
-
* [
|
29
|
-
|
30
|
-
* [Versioning](#versioning)
|
25
|
+
* [Integrating Contingency Yourself](#integrating-contingency-yourself)
|
26
|
+
* [Integration API](#three-integration-methods)
|
27
|
+
* [Please Contribute](#please-contribute)
|
28
|
+
* [Versioning](#versioning)s
|
31
29
|
* [Contingency Versioning](#contingency-versioning)
|
32
30
|
* [Integration Versioning](#contingency-integration-versioning)
|
33
31
|
* [Contributing Integrations](#contributing-integrations)
|
@@ -40,12 +38,11 @@ Experience true freedom, and make yourself a Contingency Plan.
|
|
40
38
|
## Installation
|
41
39
|
</a>
|
42
40
|
|
43
|
-
Add
|
41
|
+
Add this line to your application's Gemfile:
|
44
42
|
|
45
|
-
gem 'contingency',
|
46
|
-
gem 'contingency_my-framework-name', '~> x.0'
|
43
|
+
gem 'contingency-my_framework_name', '~> x.0', require: 'contingency/adapters/my_framework_name'
|
47
44
|
|
48
|
-
...where [
|
45
|
+
...where [`my_framework_name`](#supported-integrations) is the name of your framework, and `x` is the major version of the framework you're using.
|
49
46
|
|
50
47
|
Then, execute:
|
51
48
|
|
@@ -64,22 +61,22 @@ Contingency
|
|
64
61
|
<table>
|
65
62
|
<thead>
|
66
63
|
<tr>
|
67
|
-
<td>
|
64
|
+
<td>Integration</td>
|
68
65
|
<td>Integration Quality</td>
|
69
|
-
<td>
|
66
|
+
<td>Supported Versions</td>
|
70
67
|
<td>Maintainer</td>
|
71
68
|
</tr>
|
72
69
|
</thead>
|
73
70
|
<tbody>
|
74
71
|
<tr>
|
75
72
|
<td>
|
76
|
-
<a href='
|
73
|
+
<a href='https://www.github.com/christhekeele/contingency_rails'>Rails</a>
|
77
74
|
</td>
|
78
75
|
<td>
|
79
|
-
|
76
|
+
**Bad**
|
80
77
|
</td>
|
81
78
|
<td>
|
82
|
-
<a href='https://
|
79
|
+
<a href='https://rubygems.org/gems/contingency_rails'>3.x</a>
|
83
80
|
</td>
|
84
81
|
<td>
|
85
82
|
<a href='https://www.github.com/christhekeele/contingency_rails/issues'>christhekeele</a>
|
@@ -88,30 +85,23 @@ Contingency
|
|
88
85
|
</tbody>
|
89
86
|
</table>
|
90
87
|
|
91
|
-
|
92
|
-
### Rails
|
93
|
-
</a>
|
94
|
-
|
95
|
-
<a name='custom-integrations'>
|
96
|
-
## Custom Integrations
|
97
|
-
</a>
|
98
|
-
|
99
|
-
If the framework you're using doesn't have a Contingency Plan integration, you're only 3 methods away from integrating it yourself.
|
88
|
+
**Great** integrations have functional tests and good documentation, **good** integrations only have functional tests, **poor** integrations only have documentaion, and **bad** ones have neither.
|
100
89
|
|
101
90
|
<a name='integrating-contingency-yourself'>
|
102
|
-
|
91
|
+
## Integrating it Yourself
|
103
92
|
</a>
|
104
93
|
|
105
|
-
|
94
|
+
If the framework you're using doesn't have a Contingency integration, you're only 3 methods away from integrating it yourself.
|
106
95
|
|
107
96
|
<a name='three-integration-methods'>
|
108
|
-
|
97
|
+
### Integration API
|
109
98
|
</a>
|
110
99
|
|
111
|
-
<a name='
|
100
|
+
<a name='please-contribute'>
|
101
|
+
### Please Contribute
|
112
102
|
</a>
|
113
103
|
|
114
|
-
If you decide to go through this trouble, you really should consider [contributing your Contingency
|
104
|
+
If you decide to go through this trouble, you really should consider [contributing your Contingency integration](#contributing-integrations) to Contingency.</a>
|
115
105
|
|
116
106
|
<a name='versioning'>
|
117
107
|
## Versioning
|
@@ -127,31 +117,7 @@ Contingency itself is versioned as it changes. It bumps its major version as its
|
|
127
117
|
### Integration Versioning
|
128
118
|
</a>
|
129
119
|
|
130
|
-
|
131
|
-
#### Great
|
132
|
-
</a>
|
133
|
-
|
134
|
-
Contingency Plans should be versioned [with their frameworks](#supported-integrations). Integrations that follow this simple requirement are labeled as [**great**](#supported-integrations).
|
135
|
-
|
136
|
-
<a name='good-dependency-management'>
|
137
|
-
#### Good
|
138
|
-
</a>
|
139
|
-
|
140
|
-
Contingency Plans that keep up with at least [the major version of their framework](http://http://semver.org/) will result in the integration being labeled as [**good**](#supported-integrations).
|
141
|
-
|
142
|
-
<a name='poor-dependency-management'>
|
143
|
-
#### Poor
|
144
|
-
</a>
|
145
|
-
|
146
|
-
Contingency Plans that fail to keep up with [the major version of their framework](http://http://semver.org/) will result in the integration being labeled as [**poor**](#supported-integrations).
|
147
|
-
|
148
|
-
<a name='bad-dependency-management'>
|
149
|
-
#### Bad
|
150
|
-
</a>
|
151
|
-
|
152
|
-
Contingency Plans that throw off the shackles of [symantic versioning](http://http://semver.org/) and don't follow it from the get-go, Pull Request, or fall very behind will result in the integration being labeled as [**bad**](#supported-integrations).
|
153
|
-
|
154
|
-
I keep up with these frameworks through [the Bundle Scout](https://bundlescout.com). You should, too! **Checkest thineself lest thy wrekest thineself**.
|
120
|
+
Contingency integrations should take their major version number from [their frameworks](#supported-integrations). The rest is up to the maintainer.
|
155
121
|
|
156
122
|
<a name='contributing-integrations'>
|
157
123
|
## Contributing Integrations
|
@@ -162,14 +128,13 @@ See [contingency_rails](https://www.github.com/christhekeele/contingency_rails)
|
|
162
128
|
1. Create a new gem named after your framework (`bundle gem contingency-my_integration`)
|
163
129
|
1. Add Contingency as a dependency to your gemspec and bundle install
|
164
130
|
1. Generate an integration template (`bundle exec rake contingency:generate:plan[my_integration]`)
|
165
|
-
1. Implement the 3 methods that rake instructs you to
|
131
|
+
1. Implement the 3 API methods that rake instructs you to
|
166
132
|
1. Commit your changes (`git commit -am 'Created my_integration'`)
|
167
133
|
1. Push (`git push origin master`)
|
168
|
-
1. Follow [the steps below](#contributing-to-contingency) to add autoloading your Contingency Plan in Contingency core and wait get your Pull Request accepted
|
169
134
|
1. Create the intital build of your gem (`gem build contingency-my_integration`)
|
170
135
|
1. Release your gem (`gem push contingency-my_integration.gem`)
|
171
|
-
1. Revel in the fact that you've provided a Contingency
|
172
|
-
1.
|
136
|
+
1. Revel in the fact that you've provided a Contingency plan for you and yours
|
137
|
+
1. Follow [the steps below](#contributing-to-contingency) to update this README with links to your Contingency integrationaccepted
|
173
138
|
|
174
139
|
|
175
140
|
<a name='contributing-to-contingency'>
|
@@ -178,13 +143,10 @@ See [contingency_rails](https://www.github.com/christhekeele/contingency_rails)
|
|
178
143
|
|
179
144
|
1. Fork it
|
180
145
|
1. Create your feature branch (`git checkout -b my-new-feature`)
|
181
|
-
1. Add the name of your integration to the integrations array in the contingency/integration.rb file if [you're contributing a Contingency
|
146
|
+
1. Add the name of your integration to the integrations array in the contingency/integration.rb file if [you're contributing a Contingency integration](#contributing-integrations)
|
182
147
|
1. Commit your changes (`git commit -am 'Add some feature'`)
|
183
148
|
1. Push to the branch (`git push origin my-new-feature`)
|
184
149
|
1. Create new Pull Request
|
185
|
-
1. I tell you to go back and write some tests if you haven't already
|
186
|
-
1. I tell you to go back and update the README.md if you haven't already
|
187
|
-
1. I accept your Pull Request
|
188
150
|
|
189
151
|
<a name='credits'>
|
190
152
|
## Credits
|
@@ -194,11 +156,10 @@ See [contingency_rails](https://www.github.com/christhekeele/contingency_rails)
|
|
194
156
|
### Contributers
|
195
157
|
</a>
|
196
158
|
|
197
|
-
* None, aside from [the creator](https://www.github.com/christhekeele
|
159
|
+
* None, aside from [the creator](https://www.github.com/christhekeele). [Be the first!](#contributing-to-contingency)!
|
198
160
|
|
199
161
|
<a name='shout-outs'>
|
200
162
|
### Shout-Outs
|
201
163
|
</a>
|
202
164
|
|
203
|
-
* Thanks to [nathanl](https://github.com/nathanl) and his excellent authorization gem, [Authority](https://github.com/nathanl/authority), the structure of which inspired this one.
|
204
165
|
* Thanks to [ryanb](https://github.com/ryanb), and his subscription-worthy [Railscasts](http://railscasts.com/), which have inspired us all. Especially us [Pro users](http://railscasts.com/pro).
|
@@ -3,44 +3,36 @@ module Contingency
|
|
3
3
|
module Adapters
|
4
4
|
module Interface
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
included do
|
9
|
-
class InterfaceNotImplementedError < NotImplementedError; end
|
10
|
-
end
|
11
|
-
|
12
|
-
###
|
13
|
-
# Required integration methods go here.
|
14
|
-
# They're implemented here as no-ops that raise an error so
|
15
|
-
# all subclasses have to define them.
|
16
|
-
#
|
6
|
+
class InterfaceNotImplementedError < NotImplementedError; end
|
17
7
|
|
18
8
|
module ClassMethods
|
19
9
|
def catch_errors?
|
20
|
-
raise InterfaceNotImplementedError,
|
21
|
-
|
22
|
-
|
10
|
+
raise InterfaceNotImplementedError,
|
11
|
+
"Override this `catch_errors?` method" \
|
12
|
+
" with one that decides if your framework should activate" \
|
13
|
+
" Contingency or not (ie `ENV[RACK_ENV] !== 'development'`)."
|
23
14
|
end
|
24
15
|
end
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
17
|
+
def self.included(base)
|
18
|
+
base.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
def error_renderer(code)
|
22
|
+
raise InterfaceNotImplementedError,
|
23
|
+
"Override this `error_renderer` method" \
|
24
|
+
" with one that expects an error code," \
|
25
|
+
" and uses your framework's render syntax" \
|
26
|
+
" to render Contingency.configuration.error_template."
|
27
|
+
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
" (ie `render status: code, text: Contingency.configuration.error_template`)"
|
29
|
+
def failure_renderer(code)
|
30
|
+
raise InterfaceNotImplementedError,
|
31
|
+
"Override this `failure_renderer` method" \
|
32
|
+
" with one that expects an error code," \
|
33
|
+
" and uses your framework's render syntax"
|
34
|
+
" to display `Contingency.configuration.failure_message`."
|
42
35
|
|
43
|
-
end
|
44
36
|
end
|
45
37
|
|
46
38
|
end
|
data/lib/contingency/plan.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
module Contingency
|
2
2
|
|
3
3
|
module Plan
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
extend ActiveSupport::Rescuable
|
6
4
|
|
5
|
+
def self.included(base)
|
6
|
+
base.send(:include, Contingency.adapter)
|
7
|
+
base.extend ActiveSupport::Rescuable
|
7
8
|
|
8
|
-
|
9
|
-
extend Contingency.adapter
|
10
|
-
|
11
|
-
if catch_errors?
|
9
|
+
if base.catch_errors?
|
12
10
|
Contingency.configuration.errors.each do |code, exceptions|
|
13
|
-
rescue_from *exceptions, with: ->(exception){ render_error code, exception }
|
11
|
+
base.rescue_from *exceptions, with: ->(exception){ render_error code, exception }
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
data/lib/contingency/version.rb
CHANGED
data/lib/contingency.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_support/concern'
|
2
1
|
require 'active_support/rescuable'
|
3
2
|
require 'logger'
|
4
3
|
require "contingency/exceptions"
|
@@ -7,18 +6,16 @@ require "contingency/adapters/interface"
|
|
7
6
|
module Contingency
|
8
7
|
|
9
8
|
class << self
|
10
|
-
alias :configure :initialize
|
11
9
|
attr_accessor :configuration
|
12
10
|
attr_accessor :adapter, :adapters
|
13
11
|
end
|
14
12
|
|
15
|
-
self.adapters =
|
13
|
+
self.adapters = Contingency::Adapters.constants.reject{ |a| a == :Interface }
|
16
14
|
|
17
15
|
def self.configure
|
18
|
-
self.adapter ||= self.adapters.first || Adapters::Interface
|
19
|
-
self.configuration ||= Configuration.new
|
16
|
+
self.adapter ||= Contingency::Adapters.const_get self.adapters.first || Adapters::Interface
|
17
|
+
self.configuration ||= defined?(self.adapter::Configuration) ? self.adapter::Configuration.new : Configuration.new
|
20
18
|
|
21
|
-
yield(self.adapter.default_configuration) if self.adapter.respond_to?(:default_configuration)
|
22
19
|
yield(configuration) if block_given?
|
23
20
|
|
24
21
|
require "contingency/plan"
|