rescuable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +13 -0
- data/.gitignore +4 -0
- data/CONTRIBUTING.md +39 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/Rakefile +9 -0
- data/config/locales/en.yml +5 -0
- data/lib/rescuable.rb +14 -0
- data/lib/rescuable/engine.rb +17 -0
- data/lib/rescuable/error.rb +40 -0
- data/lib/rescuable/rails/renderer_controller.rb +29 -0
- data/lib/rescuable/record_error.rb +13 -0
- data/lib/rescuable/version.rb +8 -0
- data/rescuable.gemspec +28 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8dad4e210462d824a2f6ce7107a62a1fe8c33d21
|
4
|
+
data.tar.gz: e286e25d5fa6a2c913346fd661549ac0a0a7be14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c7f62c62080e2b94321582d65bf2b505eb4acf06a16911fa6c425d3bb4bdd15a29eaeff6dfeb891da8c9cb47ed288ca925f1acd37125a91134bd6979c28bb2c
|
7
|
+
data.tar.gz: 5bc65dfd0d746afc9b37db710aa13aefa7cb5f45c6ae6e9acfbe030c1e9042644896ae434db2d0c347891a41fc6a7e12adc50f9bf5c46682c239d05c6b324c3f
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## Issues
|
4
|
+
|
5
|
+
If you want to request a feature or report a bug, please use the following template.
|
6
|
+
|
7
|
+
```markdown
|
8
|
+
## Description
|
9
|
+
|
10
|
+
[Add feature/bug description here]
|
11
|
+
|
12
|
+
## How to reproduce
|
13
|
+
|
14
|
+
[Add steps on how to reproduce this issue]
|
15
|
+
|
16
|
+
## What do you expect
|
17
|
+
|
18
|
+
[Describe what do you expect to happen]
|
19
|
+
|
20
|
+
## What happened instead
|
21
|
+
|
22
|
+
[Describe the actual results]
|
23
|
+
|
24
|
+
## Gem version:
|
25
|
+
|
26
|
+
Rescuable version: [Add gem version here]
|
27
|
+
```
|
28
|
+
|
29
|
+
## Writing code
|
30
|
+
|
31
|
+
Once you've made your great commits (include tests, please):
|
32
|
+
|
33
|
+
1. [Fork](http://help.github.com/forking/) the [original repository](http://github.com/dhyegofernando/rescuable)
|
34
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
35
|
+
3. Push to your branch - `git push origin my_branch`
|
36
|
+
4. [Create an Issue](http://github.com/dhyegofernando/rescuable/issues) with a link to your branch
|
37
|
+
5. That's it!
|
38
|
+
|
39
|
+
Please respect the code style using [editorconfig](http://editorconfig.org/) in your text editor.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Dhyego Fernando
|
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
ADDED
data/Rakefile
ADDED
data/lib/rescuable.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require 'active_support/lazy_load_hooks'
|
4
|
+
require 'active_support/dependencies/autoload'
|
5
|
+
|
6
|
+
module Rescuable
|
7
|
+
extend ActiveSupport::Autoload
|
8
|
+
|
9
|
+
autoload :Error
|
10
|
+
autoload :RecordError
|
11
|
+
autoload :Version
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rescuable/engine'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rescuable/rails/renderer_controller'
|
2
|
+
|
3
|
+
module Rescuable
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer 'rescuable.locales' do |app|
|
6
|
+
if app.config.i18n.fallbacks.blank?
|
7
|
+
app.config.i18n.fallbacks = [:en]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer 'rescuable.helpers' do
|
12
|
+
ActiveSupport.on_load(:action_controller) do
|
13
|
+
include Rescuable::Rails::RendererController
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rescuable
|
2
|
+
class Error
|
3
|
+
include ActiveModel::Serializers::JSON
|
4
|
+
|
5
|
+
DEFAULT_ERROR_MESSAGE = 'Something went wrong'.freeze
|
6
|
+
|
7
|
+
cattr_accessor :statuses
|
8
|
+
@@statuses = Hash.new(:internal_server_error)
|
9
|
+
@@statuses.merge!(
|
10
|
+
invalid_record: :unprocessable_entity
|
11
|
+
)
|
12
|
+
|
13
|
+
attr_accessor :id, :message, :status
|
14
|
+
|
15
|
+
def initialize(id, options = {})
|
16
|
+
@id = id
|
17
|
+
@message = options[:message]
|
18
|
+
@status = options[:status]
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
@status || @@statuses[@id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
@message || I18n.t(@id, :default => [:default, DEFAULT_ERROR_MESSAGE], :scope => 'rescuable.errors.messages')
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes
|
30
|
+
{
|
31
|
+
id: id,
|
32
|
+
message: message
|
33
|
+
}.with_indifferent_access
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_error
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rescuable
|
2
|
+
module Rails
|
3
|
+
module RendererController
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def rescuable_error(error, status)
|
8
|
+
Error.statuses.merge!(error.to_sym => status)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def error_renderer(error)
|
15
|
+
render json: error.to_json, status: error.status
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_error(error, **args)
|
19
|
+
error = Error.new(error, **args) unless error.respond_to?(:to_error)
|
20
|
+
error = error.to_error
|
21
|
+
error_renderer error
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_record_error(record)
|
25
|
+
render_error RecordError.new(record)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/rescuable.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require './lib/rescuable/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rescuable'
|
5
|
+
spec.version = Rescuable::Version::STRING
|
6
|
+
spec.authors = ['Dhyego Fernando']
|
7
|
+
spec.email = ['dhyegofernando@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Render an error in JSON format with support for I18n.'
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = 'http://github.com/dhyegofernando/rescuable'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = 'exe'
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'i18n', '~> 0.6'
|
20
|
+
spec.add_dependency 'activesupport', '~> 4.0'
|
21
|
+
spec.add_dependency 'railties', '~> 4.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'minitest'
|
26
|
+
spec.add_development_dependency 'minitest-utils'
|
27
|
+
spec.add_development_dependency 'pry-meta'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rescuable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dhyego Fernando
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-utils
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-meta
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Render an error in JSON format with support for I18n.
|
126
|
+
email:
|
127
|
+
- dhyegofernando@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".editorconfig"
|
133
|
+
- ".gitignore"
|
134
|
+
- CONTRIBUTING.md
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- config/locales/en.yml
|
140
|
+
- lib/rescuable.rb
|
141
|
+
- lib/rescuable/engine.rb
|
142
|
+
- lib/rescuable/error.rb
|
143
|
+
- lib/rescuable/rails/renderer_controller.rb
|
144
|
+
- lib/rescuable/record_error.rb
|
145
|
+
- lib/rescuable/version.rb
|
146
|
+
- rescuable.gemspec
|
147
|
+
homepage: http://github.com/dhyegofernando/rescuable
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.4.6
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Render an error in JSON format with support for I18n.
|
171
|
+
test_files: []
|