kinetic_cafe_error 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.autotest +35 -0
- data/.gemtest +1 -0
- data/.travis.yml +39 -0
- data/Contributing.rdoc +62 -0
- data/Gemfile +9 -0
- data/History.rdoc +6 -0
- data/Licence.rdoc +27 -0
- data/Manifest.txt +25 -0
- data/README.rdoc +32 -0
- data/Rakefile +67 -0
- data/app/controllers/concerns/kinetic_cafe/error_handler.rb +60 -0
- data/app/views/kinetic_cafe/error/page.html.erb +8 -0
- data/config/locales/kinetic_cafe_error.en.yml +21 -0
- data/config/locales/kinetic_cafe_error.en_ca.yml +21 -0
- data/config/locales/kinetic_cafe_error.en_uk.yml +21 -0
- data/config/locales/kinetic_cafe_error.en_us.yml +21 -0
- data/config/locales/kinetic_cafe_error.fr.yml +21 -0
- data/config/locales/kinetic_cafe_error.fr_ca.yml +21 -0
- data/lib/kinetic_cafe/error.rb +217 -0
- data/lib/kinetic_cafe/error_dsl.rb +165 -0
- data/lib/kinetic_cafe/error_engine.rb +6 -0
- data/lib/kinetic_cafe_error.rb +2 -0
- data/test/test_helper.rb +15 -0
- data/test/test_kinetic_cafe_error.rb +81 -0
- data/test/test_kinetic_cafe_error_dsl.rb +218 -0
- metadata +305 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4b38a445d6682e36980b4f97aff27e7a6b0c840
|
4
|
+
data.tar.gz: 520d499da38abbdf6bf2fd73bfa842205a9c167c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed26cb24789537f5f94e7e71587bd6220acf2f6ed04bbb8d604e6c623dbd132a4f74dc1c260445f3431128b3ed606408ae89861286c9918269591ed6c4d0c8e2
|
7
|
+
data.tar.gz: d0bd5e3fd993033ab84742a62aecd482caf3f95c0933f1fd248d8dbc0e87ffd345570bdf3289c1d3af83e6cf4a2573852b55966666f945bd8d89421c91be433d
|
data/.autotest
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/bundler'
|
4
|
+
require 'autotest/restart'
|
5
|
+
require 'autotest/timestamp'
|
6
|
+
|
7
|
+
def require_plugin(resource)
|
8
|
+
require resource
|
9
|
+
rescue LoadError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
require_plugin 'autotest/clear'
|
14
|
+
|
15
|
+
Autotest.add_hook :initialize do |at|
|
16
|
+
# at.testlib = "minitest/unit"
|
17
|
+
#
|
18
|
+
# at.extra_files << "../some/external/dependency.rb"
|
19
|
+
#
|
20
|
+
# at.libs << ":../some/external"
|
21
|
+
#
|
22
|
+
# at.add_exception "vendor"
|
23
|
+
#
|
24
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
25
|
+
# at.files_matching(/test_.*rb$/)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# %w(TestA TestB).each do |klass|
|
29
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
30
|
+
# end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Autotest.add_hook :run_command do |at|
|
34
|
+
# system "rake build"
|
35
|
+
# end
|
data/.gemtest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.2.2
|
5
|
+
- 2.1.6
|
6
|
+
- 2.0.0
|
7
|
+
- 1.9.3
|
8
|
+
- jruby-1.7
|
9
|
+
- jruby-9.0.0.0.pre2
|
10
|
+
- jruby-19mode
|
11
|
+
- jruby-head
|
12
|
+
- ruby-head
|
13
|
+
- rbx-2
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: rbx-2
|
17
|
+
- rvm: jruby-head
|
18
|
+
- rvm: jruby-9.0.0.0.pre2
|
19
|
+
- rvm: ruby-head
|
20
|
+
gemfile:
|
21
|
+
- Gemfile
|
22
|
+
before_script:
|
23
|
+
- |
|
24
|
+
case "${TRAVIS_RUBY_VERSION}" in
|
25
|
+
rbx*)
|
26
|
+
gem install psych
|
27
|
+
;;
|
28
|
+
esac
|
29
|
+
- rake travis:before -t
|
30
|
+
script: rake travis
|
31
|
+
after_script:
|
32
|
+
- rake travis:after -t
|
33
|
+
notifications:
|
34
|
+
email:
|
35
|
+
recipients:
|
36
|
+
- FIX@example.com
|
37
|
+
on_success: change
|
38
|
+
on_failure: always
|
39
|
+
sudo: false
|
data/Contributing.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
== Contributing
|
2
|
+
|
3
|
+
I value any contribution to kinetic_cafe_error you can provide: a bug report, a
|
4
|
+
feature request, or code contributions.
|
5
|
+
|
6
|
+
* Changes *will* *not* be accepted without tests. The test suite is written
|
7
|
+
with {Minitest}[https://github.com/seattlerb/minitest].
|
8
|
+
* Match my coding style.
|
9
|
+
* Use a thoughtfully-named topic branch that contains your change. Rebase your
|
10
|
+
commits into logical chunks as necessary.
|
11
|
+
* Use {quality commit messages}[http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html].
|
12
|
+
* Do not change the version number; when your patch is accepted and a release
|
13
|
+
is made, the version will be updated at that point.
|
14
|
+
* Submit a GitHub pull request with your changes.
|
15
|
+
* New behaviours require new or updated documentation.
|
16
|
+
|
17
|
+
=== Test Dependencies
|
18
|
+
|
19
|
+
kinetic_cafe_error uses Ryan Davis’s {Hoe}[https://github.com/seattlerb/hoe]
|
20
|
+
to manage the release process, and it adds a number of rake tasks. You will
|
21
|
+
mostly be interested in:
|
22
|
+
|
23
|
+
$ rake
|
24
|
+
|
25
|
+
which runs the tests the same way that:
|
26
|
+
|
27
|
+
$ rake test
|
28
|
+
$ rake travis
|
29
|
+
|
30
|
+
will do.
|
31
|
+
|
32
|
+
To assist with the installation of the development dependencies for
|
33
|
+
kinetic_cafe_error, I have provided the simplest possible Gemfile pointing to
|
34
|
+
the (generated) +kinetic_cafe_error.gemspec+ file. This will permit you to do:
|
35
|
+
|
36
|
+
$ bundle install
|
37
|
+
|
38
|
+
to get the development dependencies. If you aleady have +hoe+ installed, you
|
39
|
+
can accomplish the same thing with:
|
40
|
+
|
41
|
+
$ rake newb
|
42
|
+
|
43
|
+
This task will install any missing dependencies, run the tests/specs, and
|
44
|
+
generate the RDoc.
|
45
|
+
|
46
|
+
=== Workflow
|
47
|
+
|
48
|
+
Here's the most direct way to get your work merged into the project:
|
49
|
+
|
50
|
+
* Fork the project.
|
51
|
+
* Clone down your fork (<tt>git clone git://github.com/<username>/kinetic_cafe_error.git</tt>).
|
52
|
+
* Create a topic branch to contain your change (<tt>git checkout -b my\_awesome\_feature</tt>).
|
53
|
+
* Hack away, add tests. Not necessarily in that order.
|
54
|
+
* Make sure everything still passes by running +rake+.
|
55
|
+
* If necessary, rebase your commits into logical chunks, without errors.
|
56
|
+
* Push the branch up (<tt>git push origin my\_awesome\_feature</tt>).
|
57
|
+
* Create a pull request against halostatue/kinetic_cafe_error and describe
|
58
|
+
what your change does and the why you think it should be merged.
|
59
|
+
|
60
|
+
=== Contributors
|
61
|
+
|
62
|
+
* Austin Ziegler created kinetic_cafe_error.
|
data/Gemfile
ADDED
data/History.rdoc
ADDED
data/Licence.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
== Licence
|
2
|
+
|
3
|
+
This software is available under an MIT-style licence.
|
4
|
+
|
5
|
+
* Copyright 2015 Austin Ziegler & Kinetic Cafe
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
8
|
+
this software and associated documentation files (the "Software"), to deal in
|
9
|
+
the Software without restriction, including without limitation the rights to
|
10
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
11
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
12
|
+
so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The names of its contributors may not be used to endorse or promote
|
15
|
+
products derived from this software without specific prior written
|
16
|
+
permission.
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
19
|
+
copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27
|
+
SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
.autotest
|
2
|
+
.gemtest
|
3
|
+
.travis.yml
|
4
|
+
Contributing.rdoc
|
5
|
+
Gemfile
|
6
|
+
History.rdoc
|
7
|
+
Licence.rdoc
|
8
|
+
Manifest.txt
|
9
|
+
README.rdoc
|
10
|
+
Rakefile
|
11
|
+
app/controllers/concerns/kinetic_cafe/error_handler.rb
|
12
|
+
app/views/kinetic_cafe/error/page.html.erb
|
13
|
+
config/locales/kinetic_cafe_error.en.yml
|
14
|
+
config/locales/kinetic_cafe_error.en_ca.yml
|
15
|
+
config/locales/kinetic_cafe_error.en_uk.yml
|
16
|
+
config/locales/kinetic_cafe_error.en_us.yml
|
17
|
+
config/locales/kinetic_cafe_error.fr.yml
|
18
|
+
config/locales/kinetic_cafe_error.fr_ca.yml
|
19
|
+
lib/kinetic_cafe/error.rb
|
20
|
+
lib/kinetic_cafe/error_dsl.rb
|
21
|
+
lib/kinetic_cafe/error_engine.rb
|
22
|
+
lib/kinetic_cafe_error.rb
|
23
|
+
test/test_helper.rb
|
24
|
+
test/test_kinetic_cafe_error.rb
|
25
|
+
test/test_kinetic_cafe_error_dsl.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= kinetic_cafe_error
|
2
|
+
|
3
|
+
code :: https://github.com/KineticCafe/kinetic_cafe_error/
|
4
|
+
bugs :: https://github.com/KineticCafe/kinetic_cafe_error/issues
|
5
|
+
continuous integration :: {<img src="https://travis-ci.org/KineticCafe/kinetic_cafe_error.png" />}[https://travis-ci.org/KineticCafe/kinetic_cafe_error]
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
kinetic_cafe_error provides an API-smart error base class and a DSL for
|
10
|
+
defining errors. Under Rails, it also provides a controller concern
|
11
|
+
(KineticCafe::ErrorHandler) that has a useful implementation of +rescue_from+
|
12
|
+
for KineticCafe::Error types.
|
13
|
+
|
14
|
+
== Synopsis
|
15
|
+
|
16
|
+
class MyErrorBase < KineticCafe::Error
|
17
|
+
extend KineticCafe::ErrorDSL
|
18
|
+
|
19
|
+
not_found class: :user # => MyErrorBase::UserNotFound
|
20
|
+
unauthorized class: :user # => MyErrorBase::UserUnauthorized
|
21
|
+
forbidden class: :user # => MyErrorBase::UserForbidden
|
22
|
+
conflict class: :user# => MyErrorBase::UserConflict
|
23
|
+
end
|
24
|
+
|
25
|
+
== Install
|
26
|
+
|
27
|
+
Add kinetic_cafe_error to your gemfile:
|
28
|
+
|
29
|
+
gem 'kinetic_cafe_error', '~> 1.0'
|
30
|
+
|
31
|
+
:include: Contributing.rdoc
|
32
|
+
:include: Licence.rdoc
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'rake/clean'
|
6
|
+
|
7
|
+
Hoe.plugin :doofus
|
8
|
+
Hoe.plugin :gemspec2
|
9
|
+
Hoe.plugin :git
|
10
|
+
Hoe.plugin :minitest
|
11
|
+
Hoe.plugin :travis
|
12
|
+
Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
|
13
|
+
|
14
|
+
spec = Hoe.spec "kinetic_cafe_error" do
|
15
|
+
# HEY! If you fill these out in ~/.hoe_template/minitest-travis/Rakefile.erb,
|
16
|
+
# you'll never have to touch them again!
|
17
|
+
# (delete this comment too, of course)
|
18
|
+
developer('Austin Ziegler', 'aziegler@kineticcafe.com')
|
19
|
+
|
20
|
+
require_ruby_version '>= 1.9.2'
|
21
|
+
|
22
|
+
self.history_file = 'History.rdoc'
|
23
|
+
self.readme_file = 'README.rdoc'
|
24
|
+
self.extra_rdoc_files = FileList["*.rdoc"].to_a
|
25
|
+
|
26
|
+
license "MIT"
|
27
|
+
|
28
|
+
extra_dev_deps << ['hoe-doofus', '~> 1.0']
|
29
|
+
extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
|
30
|
+
extra_dev_deps << ['hoe-git', '~> 1.6']
|
31
|
+
extra_dev_deps << ['hoe-rubygems', '~> 1.0']
|
32
|
+
extra_dev_deps << ['hoe-travis', '~> 1.2']
|
33
|
+
extra_dev_deps << ['minitest', '~> 5.4']
|
34
|
+
extra_dev_deps << ['minitest-autotest', '~> 1.0']
|
35
|
+
extra_dev_deps << ['minitest-focus', '~> 1.1']
|
36
|
+
extra_dev_deps << ['minitest-moar', '~> 0.0']
|
37
|
+
extra_dev_deps << ['minitest-stub-const', '~> 0.4']
|
38
|
+
extra_dev_deps << ['rack-test', '~> 0.6']
|
39
|
+
extra_dev_deps << ['rake', '~> 10.0']
|
40
|
+
extra_dev_deps << ['simplecov', '~> 0.7']
|
41
|
+
extra_dev_deps << ['coveralls', '~> 0.8']
|
42
|
+
end
|
43
|
+
|
44
|
+
namespace :test do
|
45
|
+
task :coverage do
|
46
|
+
spec.test_prelude = [
|
47
|
+
'require "simplecov"',
|
48
|
+
'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
|
49
|
+
'gem "minitest"'
|
50
|
+
].join('; ')
|
51
|
+
Rake::Task['test'].execute
|
52
|
+
end
|
53
|
+
|
54
|
+
task :coveralls do
|
55
|
+
spec.test_prelude = [
|
56
|
+
'require "psych"',
|
57
|
+
'require "simplecov"',
|
58
|
+
'require "coveralls"',
|
59
|
+
'SimpleCov.formatter = Coveralls::SimpleCov::Formatter',
|
60
|
+
'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
|
61
|
+
'gem "minitest"'
|
62
|
+
].join('; ')
|
63
|
+
Rake::Task['test'].execute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
# A controller concern for KineticCafe::Error that rescues from
|
4
|
+
# KineticCafe::Error using #kinetic_cafe_error_handler. This handler can be
|
5
|
+
# redefined on a per-controller basis.
|
6
|
+
module KineticCafe::ErrorHandler
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
rescue_from KineticCafe::Error, with: :kinetic_cafe_error_handler
|
11
|
+
end
|
12
|
+
|
13
|
+
# This method is called with +error+ when Rails catches a KineticCafe::Error
|
14
|
+
# descendant. It logs the message and its cause as severity error. After
|
15
|
+
# logging, it will render to HTML or JSON.
|
16
|
+
#
|
17
|
+
# HTML is rendered with #kinetic_cafe_error_render_html. JSON is rendered
|
18
|
+
# with #kinetic_cafe_error_render_json. Either of these can be overridden in
|
19
|
+
# controllers for different behaviour.
|
20
|
+
def kinetic_cafe_error_handler(error)
|
21
|
+
Rails.logger.error(error.message)
|
22
|
+
Rails.logger.error("^-- caused by: #{error.cause.message}") if error.cause
|
23
|
+
|
24
|
+
respond_to do |format|
|
25
|
+
format.html do
|
26
|
+
kinetic_cafe_error_render_html(error)
|
27
|
+
end
|
28
|
+
format.json do
|
29
|
+
kinetic_cafe_error_render_json(error)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Render the +error+ as HTML. Uses the template +kinetic_cafe/error/page+
|
35
|
+
# with +error+ passed as a local of the same name. The render status is set
|
36
|
+
# to <tt>error.status</tt>.
|
37
|
+
def kinetic_cafe_error_render_html(error)
|
38
|
+
render template: 'kinetic_cafe/error/page', locals: { error: error },
|
39
|
+
status: error.status
|
40
|
+
end
|
41
|
+
|
42
|
+
# Render the +error+ as JSON. If it is KineticCafe::Error#header_only?, only
|
43
|
+
# a +head+ of the <tt>error.status</tt> is returned. Otherwise, the render is
|
44
|
+
# done with KineticCafe::Error#json_result.
|
45
|
+
#
|
46
|
+
# If you are overriding this because you want to add or change #json_result,
|
47
|
+
# use #error_result as the value to the +json+ parameter.
|
48
|
+
#
|
49
|
+
# def kinetic_cafe_error_render_json(error)
|
50
|
+
# render status: error.status, layout: false, json: error.error_result,
|
51
|
+
# content_type: 'application/hal+json'
|
52
|
+
# end
|
53
|
+
def kinetic_cafe_error_render_json(error)
|
54
|
+
if error.header_only?
|
55
|
+
head error.status
|
56
|
+
else
|
57
|
+
render error.json_result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<h2><%= t('kinetic_cafe_error.page.title') %></h2>
|
2
|
+
|
3
|
+
<% unless error.header_only? || error.internal? -%>
|
4
|
+
<blockquote><%= error.i18n_message %></blockquote>
|
5
|
+
<% end -%>
|
6
|
+
<%= t('kinetic_cafe_error.page.body_html') %>
|
7
|
+
<%= t('kinetic_cafe_error.page.error_table_html',
|
8
|
+
status: error.status, code: error.i18n_key) -%>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en-CA:
|
2
|
+
kinetic_cafe_error:
|
3
|
+
page:
|
4
|
+
title: >-
|
5
|
+
An error occurred.
|
6
|
+
body_html: |
|
7
|
+
<p>The person responsible has been informed.</p>
|
8
|
+
<p>I’m not allowed to say anything else.</p>
|
9
|
+
<p>…</p>
|
10
|
+
<p>OK. Just for you, here’s a bit more:</p>
|
11
|
+
error_table_html: |
|
12
|
+
<table>
|
13
|
+
<tbody>
|
14
|
+
<tr>
|
15
|
+
<th>Status</th><td> </td><td>%{status}</td>
|
16
|
+
</tr>
|
17
|
+
<tr>
|
18
|
+
<th>Code</th><td> </td><td>%{code}</td>
|
19
|
+
</tr>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en-CA:
|
2
|
+
kinetic_cafe_error:
|
3
|
+
page:
|
4
|
+
title: >-
|
5
|
+
An error occurred.
|
6
|
+
body_html: |
|
7
|
+
<p>The person responsible has been informed.</p>
|
8
|
+
<p>I’m not allowed to say anything else.</p>
|
9
|
+
<p>…</p>
|
10
|
+
<p>OK. Just for you, here’s a bit more:</p>
|
11
|
+
error_table_html: |
|
12
|
+
<table>
|
13
|
+
<tbody>
|
14
|
+
<tr>
|
15
|
+
<th>Status</th><td> </td><td>%{status}</td>
|
16
|
+
</tr>
|
17
|
+
<tr>
|
18
|
+
<th>Code</th><td> </td><td>%{code}</td>
|
19
|
+
</tr>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en-UK:
|
2
|
+
kinetic_cafe_error:
|
3
|
+
page:
|
4
|
+
title: >-
|
5
|
+
An error occurred.
|
6
|
+
body_html: |
|
7
|
+
<p>The person responsible has been informed.</p>
|
8
|
+
<p>I’m not allowed to say anything else.</p>
|
9
|
+
<p>…</p>
|
10
|
+
<p>OK. Just for you, here’s a bit more:</p>
|
11
|
+
error_table_html: |
|
12
|
+
<table>
|
13
|
+
<tbody>
|
14
|
+
<tr>
|
15
|
+
<th>Status</th><td> </td><td>%{status}</td>
|
16
|
+
</tr>
|
17
|
+
<tr>
|
18
|
+
<th>Code</th><td> </td><td>%{code}</td>
|
19
|
+
</tr>
|
20
|
+
</tbody>
|
21
|
+
</table>
|