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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dc806b74dad245da064e9ca3f750999f1bda267
4
- data.tar.gz: 6f0e255f4985f615909b206865ab34d782de4c09
3
+ metadata.gz: c0fd61e5d4325b608b2ff6566e9a35b96ed319d5
4
+ data.tar.gz: 52bb05fc01b485a4d640985497cbbec006199a7e
5
5
  SHA512:
6
- metadata.gz: cbd4b1a968ab50cff49de048bbf81ba6f79f72962b5fa6a03259bc661b4e283ec7b03dfd61fc5088f1f4edc7c253b8b7392e3cf3463aec0cd6e1aa4dc81d908c
7
- data.tar.gz: 15fba0ab5d763c73826d944dbf92f06c598f210bd378bc72b348047c038d1cc8efe0ae3a58673f4582e2dd8d3b505c2a807dc6dcf6212eae5a9cb9cb739823b7
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.
@@ -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
- error_proc = _getter(:@error_proc)
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 ]
@@ -1,5 +1,5 @@
1
1
  module Api
2
2
  module Scheme
3
- VERSION = "0.2"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
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: '0.2'
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-01 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler