api-scheme 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/api/scheme.rb +6 -1
- data/lib/api/scheme/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0fd61e5d4325b608b2ff6566e9a35b96ed319d5
|
4
|
+
data.tar.gz: 52bb05fc01b485a4d640985497cbbec006199a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0304ba3e05d26ee02d8bc2840f21ebdac93bb6b7a6d6571b3cff59921249dcc364d710862217d64387598614491d781de55b12c03467109f1a381640b6c4df84
|
7
|
+
data.tar.gz: fb84a3d697a31a0f5a37760cafdf8cf78f25101ef0f3a1672b47628b373e7af80861049ca67b153f92d07664c9ed8651756517fa4fa8c7de0cf58c8a254b8388
|
data/README.md
CHANGED
@@ -62,8 +62,12 @@ end
|
|
62
62
|
You can also use custom success, and error handlers as follows:
|
63
63
|
|
64
64
|
```ruby
|
65
|
+
error_map %W(ActionController::ParameterMissing) => 400,
|
66
|
+
%W(ActiveRecord::RecordInvalid) => 422..0
|
67
|
+
|
65
68
|
render_error_with :render_error
|
66
69
|
render_success_with :render_success
|
70
|
+
render_error_code 422..0 => :render_error
|
67
71
|
|
68
72
|
def render_error text, minor, major
|
69
73
|
render json: { text: text, code: minor }, status: major
|
@@ -72,7 +76,13 @@ You can also use custom success, and error handlers as follows:
|
|
72
76
|
def render_success data, status
|
73
77
|
render json: data, status
|
74
78
|
end
|
79
|
+
|
80
|
+
def render_invalid text, minor, major
|
81
|
+
render json: { text: text, code: minor, additional: 'invalid' }, status: major
|
82
|
+
end
|
83
|
+
|
75
84
|
```
|
85
|
+
Note, that you are able specify a method to proceed an error separately for a specific error code.
|
76
86
|
|
77
87
|
Or even define the action method yourself instead of using the defaults, thus just skip `use_actions` call,
|
78
88
|
and declare required methods excplicitly in the controller.
|
data/lib/api/scheme.rb
CHANGED
@@ -29,6 +29,10 @@ module Api::Scheme
|
|
29
29
|
@error_proc ||= method || prc
|
30
30
|
end
|
31
31
|
|
32
|
+
def render_error_code options = {}
|
33
|
+
@error_proces = (@error_proces || {}).merge(options)
|
34
|
+
end
|
35
|
+
|
32
36
|
def use_model name
|
33
37
|
@model_name = name
|
34
38
|
end
|
@@ -160,7 +164,8 @@ module Api::Scheme
|
|
160
164
|
get_code_of_error_map(e)
|
161
165
|
end
|
162
166
|
|
163
|
-
|
167
|
+
error_proces = _getter(:@error_proces)
|
168
|
+
error_proc = error_proces[code] || error_proc = _getter(:@error_proc)
|
164
169
|
|
165
170
|
prc = error_proc.kind_of?(Proc) && error_proc || self.method(error_proc.to_s.to_sym)
|
166
171
|
args = [get_code_text(code), get_sub_code(code), get_pure_code(code), code, e ]
|
data/lib/api/scheme/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-scheme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Malo Skrylevo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|