erratum_responsum 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b232b20c9ee3f0983875487e2a75b9606206e7fe6c3c8fcb5dc584fd2044208a
4
- data.tar.gz: 743cd7cc2248c193d8d545bcc8d8191c5b5b72f98f37158cbaf82e9f7cc20639
3
+ metadata.gz: ae61f3f8bab5c26e11868d4db5bb1bacb4577ef99f54735c8c97cba09f9ddd6f
4
+ data.tar.gz: ea12df44bfa78a1b9ef537495aa19fb5290a2a214a943a8255c2cce6b078878b
5
5
  SHA512:
6
- metadata.gz: 2c7ce77f5771972fd74cc2847b89854b54389cb6453825c3c4ee8df70f21bbb5b68e687de71af9549cb94eb0ff522908745cb19917ec8edc8c2372f4ef0873ac
7
- data.tar.gz: 5e3e8ee36ac979c97cbe3bab498b27b798485a2d9c6d156e60e0779aee28e16b00f0f25d038036da66076be387f9f20c0236328093bb923e94949f27cdc94294
6
+ metadata.gz: 1ea2e014aaa3f107ae89793eb1dc894cfbc8f04f0781ebea6fd9cdf86e93517b4669f6472e619654079e5acaf17101c1420692725e73cba0a466c79bfd89da74
7
+ data.tar.gz: 7817ceaa16da2513d3445e30f2fccf72478774a956ff6111e74175cf98ad657847aec6edc8d886be5f0ae57cbce7098c21d2bbaa851a7ee76d11155d56b5394e
@@ -0,0 +1,29 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+ - depfu/*
11
+ - release/*
12
+ - feature/*
13
+
14
+ jobs:
15
+ build:
16
+
17
+ runs-on: ubuntu-latest
18
+
19
+ steps:
20
+ - uses: actions/checkout@v1
21
+ - name: Set up Ruby 2.6
22
+ uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.6.x
25
+ - name: Build and test with Rake
26
+ run: |
27
+ gem install bundler
28
+ bundle install --jobs 4 --retry 3
29
+ bundle exec rake
data/.gitignore CHANGED
@@ -1,13 +1,13 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
-
11
- .idea/workspace.xml
12
- .idea/usage.statistics.xml
13
- .idea/tasks.xml
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+
11
+ .idea/workspace.xml
12
+ .idea/usage.statistics.xml
13
+ .idea/tasks.xml
data/.idea/.rakeTasks CHANGED
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <Settings><!--This file was automatically generated by Ruby plugin.
3
- You are allowed to:
4
- 1. Remove rake task
5
- 2. Add existing rake tasks
6
- To add existing rake tasks automatically delete this file and reload the project.
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
7
  --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build erratum_responsum-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install erratum_responsum-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install erratum_responsum-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push erratum_responsum-0.1.0.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -1,6 +1,6 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
- </profile>
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
6
  </component>
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at derk-jan+github@karrenbeld.info. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at derk-jan+github@karrenbeld.info. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in erratum_responsum.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in erratum_responsum.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,35 +1,36 @@
1
- PATH
2
- remote: .
3
- specs:
4
- erratum_responsum (0.1.1)
5
- activesupport (>= 4.0.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (5.2.2)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
- concurrent-ruby (1.1.4)
16
- i18n (1.5.3)
17
- concurrent-ruby (~> 1.0)
18
- minitest (5.11.3)
19
- rake (10.5.0)
20
- thread_safe (0.3.6)
21
- tzinfo (1.2.5)
22
- thread_safe (~> 0.1)
23
-
24
- PLATFORMS
25
- ruby
26
- x64-mingw32
27
-
28
- DEPENDENCIES
29
- bundler (~> 2.0)
30
- erratum_responsum!
31
- minitest (~> 5.0)
32
- rake (~> 10.0)
33
-
34
- BUNDLED WITH
35
- 2.0.1
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ erratum_responsum (0.1.1)
5
+ activesupport (>= 4.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.3.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ concurrent-ruby (1.1.8)
17
+ i18n (1.8.10)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.14.4)
20
+ rake (13.0.3)
21
+ tzinfo (2.0.4)
22
+ concurrent-ruby (~> 1.0)
23
+ zeitwerk (2.4.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+ x64-mingw32
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 2.0)
31
+ erratum_responsum!
32
+ minitest (~> 5.0)
33
+ rake (~> 13.0)
34
+
35
+ BUNDLED WITH
36
+ 2.0.1
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Derk-Jan Karrenbeld
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Derk-Jan Karrenbeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,78 +1,87 @@
1
- # ErratumResponsum
2
-
3
- [![Build Status: master](https://travis-ci.com/XPBytes/erratum_responsum.svg)](https://travis-ci.com/XPBytes/erratum_responsum)
4
- [![Gem Version](https://badge.fury.io/rb/erratum_responsum.svg)](https://badge.fury.io/rb/erratum_responsum)
5
- [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
6
-
7
- Error response handlers for a Rails controller.
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem 'erratum_responsum'
15
- ```
16
-
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install erratum_responsum
24
-
25
- ## Usage
26
-
27
- Add the concern to your `ApplicationController` or `ApiController`
28
-
29
- ```ruby
30
- require 'erratum_responsum'
31
-
32
- class ApiController < ActionController::API
33
- include ErratumResponsum
34
- end
35
- ```
36
-
37
- ### Media Type
38
-
39
- You can optionally set the class variable `error_media_type` to change the `Content-Type` of error responses.
40
- ```ruby
41
- self.error_media_type = 'application/vnd.xpbytes.errors.v1+json'
42
- ```
43
-
44
- ### Rescue Errors
45
-
46
- In order to use the error responses, use `rescue_from` to handle them:
47
-
48
- ```ruby
49
- rescue_from CanCan::AccessDenied, AuthorizedTransaction::TransactionUnauthorized, with: :forbidden
50
- rescue_from OptimisticallyStale::MissingLockVersion, ActionController::BadRequest,
51
- RequestMissingParam, with: :bad_request
52
- rescue_from ActiveRecord::RecordNotFound, with: :not_found
53
- rescue_from ActionController::UnknownFormat, NoAcceptSerializer, with: :not_acceptable
54
- rescue_from ResourceGone, with: :gone
55
- rescue_from ActiveRecord::StatementInvalid, ActiveRecord::RecordInvalid,
56
- ContentDoesNotMatchContentType, with: :unprocessable_entity
57
- rescue_from ActiveRecord::RecordNotUnique, ActiveRecord::StaleObjectError, with: :conflict
58
- rescue_from ContentTypeNotRecognised, with: :unsupported_media_type
59
- ```
60
-
61
- Now, when one of these error is raised in a controller action, the error response is generated automatically.
62
-
63
- When the exception has more information, such as an `error_code`, the code will use that instead, prefixed with `Ex`.
64
- If there is no such information, the error class name is used to generate the error code, prefixed with `Gx`.
65
- Change this behaviour by overriding `def error_code(error)`.
66
-
67
- ## Development
68
-
69
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
70
- also run `bin/console` for an interactive prompt that will allow you to experiment.
71
-
72
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
73
- version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
74
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
-
76
- ## Contributing
77
-
78
- Bug reports and pull requests are welcome on GitHub at [XPBytes/erratum_responsum](https://github.com/XPBytes/erratum_responsum).
1
+ # ErratumResponsum
2
+
3
+ [![Build Status: master](https://travis-ci.com/XPBytes/erratum_responsum.svg)](https://travis-ci.com/XPBytes/erratum_responsum)
4
+ [![Gem Version](https://badge.fury.io/rb/erratum_responsum.svg)](https://badge.fury.io/rb/erratum_responsum)
5
+ [![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
6
+
7
+ Error response handlers for a Rails controller, that always return JSON.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'erratum_responsum'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install erratum_responsum
24
+
25
+ ## Usage
26
+
27
+ Add the concern to your `ApplicationController` or `ApiController`
28
+
29
+ ```ruby
30
+ require 'erratum_responsum'
31
+
32
+ class ApiController < ActionController::API
33
+ include ErratumResponsum
34
+ end
35
+ ```
36
+
37
+ ### Media Type
38
+
39
+ You can optionally set the class variable `error_media_type` to change the `Content-Type` of error responses.
40
+
41
+ ```ruby
42
+ self.error_media_type = 'application/vnd.xpbytes.errors.v1+json'
43
+ ```
44
+
45
+ ### Rescue Errors
46
+
47
+ In order to use the error responses, use `rescue_from` to handle them:
48
+
49
+ ```ruby
50
+ rescue_from CanCan::AccessDenied, AuthorizedTransaction::TransactionUnauthorized, with: :forbidden
51
+ rescue_from OptimisticallyStale::MissingLockVersion, ActionController::BadRequest,
52
+ RequestMissingParam, with: :bad_request
53
+ rescue_from ActiveRecord::RecordNotFound, with: :not_found
54
+ rescue_from ActionController::UnknownFormat, NoAcceptSerializer, with: :not_acceptable
55
+ rescue_from ResourceGone, with: :gone
56
+ rescue_from ActiveRecord::StatementInvalid, ActiveRecord::RecordInvalid,
57
+ ContentDoesNotMatchContentType, with: :unprocessable_entity
58
+ rescue_from ActiveRecord::RecordNotUnique, ActiveRecord::StaleObjectError, with: :conflict
59
+ rescue_from ContentTypeNotRecognised, with: :unsupported_media_type
60
+ ```
61
+
62
+ Now, when one of these error is raised in a controller action, the error response is generated automatically.
63
+
64
+ > 💡 Remove `CanCan` if you don't use `cancancan`.
65
+ >
66
+ > 💡 Remove `AuthorizedTransaction` , if you don't use `authorized_transaction`.
67
+ >
68
+ > 💡 Remove `OptimisticallyStale` if you don't use `optimistically_stale`
69
+
70
+ When the exception has more information, such as an `error_code`, the code will use that instead, prefixed with `Ex`.
71
+ If there is no such information, the error class name is used to generate the error code, prefixed with `Gx`.
72
+ Change this behaviour by overriding `def error_code(error)`.
73
+
74
+ This gem does expose more errors
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies.
79
+ Then, run `rake test` to run the tests.
80
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ To install this gem onto your local machine, run `bundle exec rake install`.
83
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+
85
+ ## Contributing
86
+
87
+ Bug reports and pull requests are welcome on GitHub at [XPBytes/erratum_responsum](https://github.com/XPBytes/erratum_responsum).
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "erratum_responsum"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "erratum_responsum"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,43 +1,43 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "erratum_responsum/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "erratum_responsum"
8
- spec.version = ErratumResponsum::VERSION
9
- spec.authors = ["Derk-Jan Karrenbeld"]
10
- spec.email = ["derk-jan@xpbytes.com"]
11
-
12
- spec.summary = 'Error response handlers for a Rails controller'
13
- spec.homepage = 'https://github.com/XPBytes/erratum_responsum'
14
- spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
-
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = "https://github.com/XPBytes/erratum_responsum"
23
- spec.metadata["changelog_uri"] = "https://github.com/XPBytes/erratum_responsum/issues"
24
- else
25
- raise "RubyGems 2.0 or newer is required to protect against " \
26
- "public gem pushes."
27
- end
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
- end
34
- spec.bindir = "exe"
35
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
- spec.require_paths = ["lib"]
37
-
38
- spec.add_dependency 'activesupport', '>= 4.0.0'
39
-
40
- spec.add_development_dependency "bundler", "~> 2.0"
41
- spec.add_development_dependency "rake", "~> 10.0"
42
- spec.add_development_dependency "minitest", "~> 5.0"
43
- end
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "erratum_responsum/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "erratum_responsum"
8
+ spec.version = ErratumResponsum::VERSION
9
+ spec.authors = ["Derk-Jan Karrenbeld"]
10
+ spec.email = ["derk-jan@xpbytes.com"]
11
+
12
+ spec.summary = 'Error response handlers for a Rails controller'
13
+ spec.homepage = 'https://github.com/XPBytes/erratum_responsum'
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/XPBytes/erratum_responsum"
23
+ spec.metadata["changelog_uri"] = "https://github.com/XPBytes/erratum_responsum/issues"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency 'activesupport', '>= 4.0.0'
39
+
40
+ spec.add_development_dependency "bundler", "~> 2.0"
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ end
@@ -1,92 +1,134 @@
1
- require 'erratum_responsum/version'
2
- require 'digest'
3
-
4
- begin
5
- require 'cancancan'
6
- require 'erratum_responsum/cancancan'
7
- rescue LoadError
8
- # no-op
9
- end
10
-
11
- require 'active_support/concern'
12
- require 'active_support/core_ext/module/attribute_accessors'
13
-
14
- module ErratumResponsum
15
- extend ActiveSupport::Concern
16
-
17
- cattr_accessor :error_media_type
18
- self.error_media_type = 'application/json'
19
-
20
- # 400
21
- def bad_request(*exception)
22
- render json: { errors: serialize_errors(exception) },
23
- status: :bad_request,
24
- content_type: ErratumResponsum.error_media_type
25
- end
26
-
27
- # 403
28
- def forbidden(exception)
29
- render json: { errors: serialize_errors(exception) },
30
- status: :forbidden,
31
- content_type: ErratumResponsum.error_media_type
32
- end
33
-
34
- # 404
35
- def not_found(exception)
36
- if defined?(NothingAccessibleBy) && exception.message.include?('TRUE=FALSE')
37
- # When CanCanCan can not find a clause for an associated model, when using accessible_by, it will use TRUE=FALSE
38
- # instead of throwing a CanCan::AccessDenied.
39
- return forbidden(NothingAccessibleBy.new(exception.model))
40
- end
41
-
42
- render json: { errors: serialize_errors(exception) },
43
- status: :not_found,
44
- content_type: ErratumResponsum.error_media_type
45
- end
46
-
47
- # 406
48
- def not_acceptable(exception)
49
- render json: { errors: serialize_errors(exception) },
50
- status: :not_acceptable,
51
- content_type: ErratumResponsum.error_media_type
52
- end
53
-
54
- # 410
55
- def gone(exception)
56
- render json: { errors: serialize_errors(exception) },
57
- status: :gone,
58
- content_type: ErratumResponsum.error_media_type
59
- end
60
-
61
- # 409
62
- def conflict(exception)
63
- render json: { errors: serialize_errors(exception) },
64
- status: :conflict,
65
- content_type: ErratumResponsum.error_media_type
66
- end
67
-
68
- # 415
69
- def unsupported_media_type(exception)
70
- render json: { errors: serialize_errors(exception) },
71
- status: :unsupported_media_type,
72
- content_type: ErratumResponsum.error_media_type
73
- end
74
-
75
- # 422
76
- def unprocessable_entity(exception)
77
- render json: { errors: serialize_errors(exception) },
78
- status: :unprocessable_entity,
79
- content_type: ErratumResponsum.error_media_type
80
- end
81
-
82
- def serialize_errors(errors)
83
- Array(errors).map do |error|
84
- { message: error.respond_to?(:message) ? error.message : error, code: error_code(error) }
85
- end
86
- end
87
-
88
- def error_code(error)
89
- return 'Ex' + String(error.send(:error_code)) if error.respond_to?(:error_code)
90
- 'Gx' + Digest::MD5.hexdigest(error.class.name)
91
- end
92
- end
1
+ require 'erratum_responsum/version'
2
+ require 'digest'
3
+
4
+ begin
5
+ require 'cancancan'
6
+ require 'erratum_responsum/cancancan'
7
+ rescue LoadError
8
+ # no-op
9
+ end
10
+
11
+ require 'active_support/concern'
12
+ require 'active_support/core_ext/module/attribute_accessors'
13
+
14
+ module ErratumResponsum
15
+ extend ActiveSupport::Concern
16
+
17
+ cattr_accessor :error_media_type
18
+ self.error_media_type = 'application/json'
19
+
20
+ # 400
21
+ def bad_request(*exception)
22
+ render json: { errors: serialize_errors(exception) },
23
+ status: :bad_request,
24
+ content_type: ErratumResponsum.error_media_type
25
+ end
26
+
27
+ # 401
28
+ def unauthorized(*exception)
29
+ render json: { errors: serialize_errors(exception) },
30
+ status: :unauthorized,
31
+ content_type: ErratumResponsum.error_media_type
32
+ end
33
+
34
+ # 403
35
+ def forbidden(exception)
36
+ render json: { errors: serialize_errors(exception) },
37
+ status: :forbidden,
38
+ content_type: ErratumResponsum.error_media_type
39
+ end
40
+
41
+ # 404
42
+ def not_found(exception)
43
+ if defined?(NothingAccessibleBy) && exception.message.include?('TRUE=FALSE')
44
+ # When CanCanCan can not find a clause for an associated model, when using accessible_by, it will use TRUE=FALSE
45
+ # instead of throwing a CanCan::AccessDenied.
46
+ return forbidden(NothingAccessibleBy.new(exception.model))
47
+ end
48
+
49
+ render json: { errors: serialize_errors(exception) },
50
+ status: :not_found,
51
+ content_type: ErratumResponsum.error_media_type
52
+ end
53
+
54
+ # 405
55
+ def method_not_allowed(exception)
56
+ render json: { errors: serialize_errors(exception) },
57
+ status: :method_not_allowed,
58
+ content_type: ErratumResponsum.error_media_type
59
+ end
60
+
61
+ # 406
62
+ def not_acceptable(exception)
63
+ render json: { errors: serialize_errors(exception) },
64
+ status: :not_acceptable,
65
+ content_type: ErratumResponsum.error_media_type
66
+ end
67
+
68
+ # 409
69
+ def conflict(exception)
70
+ render json: { errors: serialize_errors(exception) },
71
+ status: :conflict,
72
+ content_type: ErratumResponsum.error_media_type
73
+ end
74
+
75
+ # 410
76
+ def gone(exception)
77
+ render json: { errors: serialize_errors(exception) },
78
+ status: :gone,
79
+ content_type: ErratumResponsum.error_media_type
80
+ end
81
+
82
+ # 415
83
+ def unsupported_media_type(exception)
84
+ render json: { errors: serialize_errors(exception) },
85
+ status: :unsupported_media_type,
86
+ content_type: ErratumResponsum.error_media_type
87
+ end
88
+
89
+ # 422
90
+ def unprocessable_entity(exception)
91
+ render json: { errors: serialize_errors(exception) },
92
+ status: :unprocessable_entity,
93
+ content_type: ErratumResponsum.error_media_type
94
+ end
95
+
96
+ # 428
97
+ def precondition_required(exception)
98
+ render json: { errors: serialize_errors(exception) },
99
+ status: :precondition_required,
100
+ content_type: ErratumResponsum.error_media_type
101
+ end
102
+
103
+ # 429
104
+ def too_many_requests(exception)
105
+ render json: { errors: serialize_errors(exception) },
106
+ status: :too_many_requests,
107
+ content_type: ErratumResponsum.error_media_type
108
+ end
109
+
110
+ # 500
111
+ def internal_server_error(exception)
112
+ render json: { errors: serialize_errors(exception) },
113
+ status: :internal_server_error,
114
+ content_type: ErratumResponsum.error_media_type
115
+ end
116
+
117
+ # 501
118
+ def not_implemented(exception)
119
+ render json: { errors: serialize_errors(exception) },
120
+ status: :not_implemented,
121
+ content_type: ErratumResponsum.error_media_type
122
+ end
123
+
124
+ def serialize_errors(errors)
125
+ Array(errors).map do |error|
126
+ { message: error.respond_to?(:message) ? error.message : error, code: error_code(error) }
127
+ end
128
+ end
129
+
130
+ def error_code(error)
131
+ return 'Ex' + String(error.send(:error_code)) if error.respond_to?(:error_code)
132
+ 'Gx' + Digest::MD5.hexdigest(error.class.name)
133
+ end
134
+ end
@@ -1,3 +1,3 @@
1
- module ErratumResponsum
2
- VERSION = "0.1.1"
3
- end
1
+ module ErratumResponsum
2
+ VERSION = "0.2.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erratum_responsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-14 00:00:00.000000000 Z
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,13 +66,14 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.0'
69
- description:
69
+ description:
70
70
  email:
71
71
  - derk-jan@xpbytes.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/ci.yml"
76
77
  - ".gitignore"
77
78
  - ".idea/.rakeTasks"
78
79
  - ".idea/dictionaries/Derk_Jan.xml"
@@ -82,7 +83,6 @@ files:
82
83
  - ".idea/modules.xml"
83
84
  - ".idea/vcs.xml"
84
85
  - ".rubocop.yml"
85
- - ".travis.yml"
86
86
  - CODE_OF_CONDUCT.md
87
87
  - Gemfile
88
88
  - Gemfile.lock
@@ -102,7 +102,7 @@ metadata:
102
102
  homepage_uri: https://github.com/XPBytes/erratum_responsum
103
103
  source_code_uri: https://github.com/XPBytes/erratum_responsum
104
104
  changelog_uri: https://github.com/XPBytes/erratum_responsum/issues
105
- post_install_message:
105
+ post_install_message:
106
106
  rdoc_options: []
107
107
  require_paths:
108
108
  - lib
@@ -117,9 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.7.6
122
- signing_key:
120
+ rubygems_version: 3.1.4
121
+ signing_key:
123
122
  specification_version: 4
124
123
  summary: Error response handlers for a Rails controller
125
124
  test_files: []
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5
7
- - 2.6
8
- - ruby-head
9
- before_install:
10
- - gem install bundler -v 2.0.1
11
- - gem update --system
12
- - gem --version
13
- matrix:
14
- allow_failures:
15
- - rvm: ruby-head
16
- install:
17
- - bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}