json_apiable 0.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/json_apiable.gemspec +4 -4
- data/lib/json_apiable/json_apiable.rb +13 -6
- data/lib/json_apiable/params_parser.rb +5 -1
- data/lib/json_apiable/renderers.rb +5 -0
- data/lib/json_apiable/version.rb +1 -1
- metadata +19 -19
- data/Gemfile.lock +0 -193
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ccd4b82cdad6de8e40b899171c1535d503e53b86a3e9524d86efc11b33a4ee
|
4
|
+
data.tar.gz: 4556e1e1416403fc695856bbe59d2e882155f3b01d575395dc61f7a872ec8b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a1990f687feec45ef3fc291296de155ad47a60e6c5f4eff5be02fdc932ba0a748a6742247d501ef97f3a6fd320da2394d417f3b71cc084d3c97c94822fb501
|
7
|
+
data.tar.gz: 759e96816c876f7f570b5d8537e0db67af61343a6878cb22ca04638aa01460c04ef83fbc9d2f3d5b8fc28463fd6566d2c9daff4b6663b3fcb29c7e29a657a86f
|
data/CHANGELOG.md
ADDED
data/json_apiable.gemspec
CHANGED
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency 'activerecord'
|
28
|
-
spec.add_dependency 'activesupport'
|
29
|
-
spec.add_dependency '
|
27
|
+
spec.add_dependency 'activerecord'
|
28
|
+
spec.add_dependency 'activesupport'
|
29
|
+
spec.add_dependency 'jsonapi-serializer'
|
30
30
|
|
31
31
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
32
|
spec.add_development_dependency 'factory_bot_rails'
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'pry-byebug'
|
36
36
|
spec.add_development_dependency 'rails'
|
37
37
|
spec.add_development_dependency 'rails-controller-testing'
|
38
|
-
spec.add_development_dependency 'rake', '~>
|
38
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
39
39
|
spec.add_development_dependency 'rspec-rails', '~> 3.9'
|
40
40
|
spec.add_development_dependency 'sqlite3'
|
41
41
|
end
|
@@ -20,6 +20,7 @@ module JsonApiable
|
|
20
20
|
|
21
21
|
rescue_from ArgumentError, with: :respond_to_bad_argument
|
22
22
|
rescue_from ActionController::UnpermittedParameters, with: :respond_to_bad_argument
|
23
|
+
rescue_from JSONAPI::Serializer::UnsupportedIncludeError, with: :respond_to_exception_raised
|
23
24
|
rescue_from MalformedRequestError, with: :respond_to_malformed_request
|
24
25
|
rescue_from UnprocessableEntityError, with: :respond_to_unprocessable_entity
|
25
26
|
rescue_from UnauthorizedError, with: :respond_to_unauthorized
|
@@ -72,23 +73,29 @@ module JsonApiable
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def jsonapi_assign_params
|
75
|
-
@jsonapi_assign_params
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
return @jsonapi_assign_params if @jsonapi_assign_params.present? && !@invalidate_assign_params
|
77
|
+
|
78
|
+
@jsonapi_assign_params = ParamsParser.parse_body_params(request,
|
79
|
+
jsonapi_build_params,
|
80
|
+
jsonapi_allowed_attributes,
|
81
|
+
jsonapi_exclude_attributes,
|
82
|
+
jsonapi_allowed_relationships,
|
83
|
+
jsonapi_exclude_relationships)
|
84
|
+
@invalidate_assign_params = false
|
85
|
+
@jsonapi_assign_params
|
81
86
|
end
|
82
87
|
|
83
88
|
def jsonapi_exclude_attribute(attrib_key)
|
84
89
|
@jsonapi_exclude_attributes ||= []
|
85
90
|
@jsonapi_exclude_attributes << attrib_key.to_sym
|
91
|
+
@invalidate_assign_params = true
|
86
92
|
jsonapi_build_params.dig(:data, :attributes, attrib_key)
|
87
93
|
end
|
88
94
|
|
89
95
|
def jsonapi_exclude_relationship(rel_key)
|
90
96
|
@jsonapi_exclude_relationships ||= []
|
91
97
|
@jsonapi_exclude_relationships << rel_key.to_sym
|
98
|
+
@invalidate_assign_params = true
|
92
99
|
jsonapi_build_params.dig(:data, :relationships, rel_key)
|
93
100
|
end
|
94
101
|
|
@@ -34,7 +34,7 @@ module JsonApiable
|
|
34
34
|
attributes&.each do |key, value|
|
35
35
|
next if excluded_attributes&.include?(key.to_sym)
|
36
36
|
|
37
|
-
new_key =
|
37
|
+
new_key = nested_attributes?(value) ? "#{key}_attributes" : key
|
38
38
|
attrs_hash[new_key] = value.is_a?(ActionController::Parameters) ? value.to_h : value
|
39
39
|
end
|
40
40
|
attrs_hash
|
@@ -78,5 +78,9 @@ module JsonApiable
|
|
78
78
|
def self.hashify(allowed_relationships)
|
79
79
|
allowed_relationships.map { |rel| { rel => {} } }
|
80
80
|
end
|
81
|
+
|
82
|
+
def self.nested_attributes?(value)
|
83
|
+
value.is_a?(ActionController::Parameters) || value.is_a?(Array)
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
@@ -32,6 +32,11 @@ module JsonApiable
|
|
32
32
|
json_render_errors json: errors, status: :bad_request
|
33
33
|
end
|
34
34
|
|
35
|
+
def respond_to_exception_raised(err_msg)
|
36
|
+
errors = [{ title: 'Invalid Argument', detail: err_msg.message }]
|
37
|
+
json_render_errors json: errors, status: :bad_request
|
38
|
+
end
|
39
|
+
|
35
40
|
def respond_to_malformed_request(err_msg = nil)
|
36
41
|
errors = [{ title: 'Malformed Request', detail: err_msg.to_s }]
|
37
42
|
json_render_errors json: errors, status: :bad_request
|
data/lib/json_apiable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_apiable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Polischuk
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: jsonapi-serializer
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '13.0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '13.0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec-rails
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +192,7 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description:
|
195
|
+
description:
|
196
196
|
email:
|
197
197
|
- mike.polis@gmail.com
|
198
198
|
executables: []
|
@@ -203,8 +203,8 @@ files:
|
|
203
203
|
- ".rspec"
|
204
204
|
- ".rubocop.yml"
|
205
205
|
- ".travis.yml"
|
206
|
+
- CHANGELOG.md
|
206
207
|
- Gemfile
|
207
|
-
- Gemfile.lock
|
208
208
|
- LICENSE.txt
|
209
209
|
- README.md
|
210
210
|
- Rakefile
|
@@ -228,7 +228,7 @@ licenses:
|
|
228
228
|
- MIT
|
229
229
|
metadata:
|
230
230
|
homepage_uri: http://github.com/mikemarsian/json_apiable
|
231
|
-
post_install_message:
|
231
|
+
post_install_message:
|
232
232
|
rdoc_options: []
|
233
233
|
require_paths:
|
234
234
|
- lib
|
@@ -243,8 +243,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
243
|
- !ruby/object:Gem::Version
|
244
244
|
version: '0'
|
245
245
|
requirements: []
|
246
|
-
rubygems_version: 3.
|
247
|
-
signing_key:
|
246
|
+
rubygems_version: 3.1.4
|
247
|
+
signing_key:
|
248
248
|
specification_version: 4
|
249
249
|
summary: Include JsonApiable module in your API::BaseController to receive a collection
|
250
250
|
of useful methods, such as arguments and relationships parser, filters, etc.
|
data/Gemfile.lock
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
json_apiable (0.4)
|
5
|
-
activerecord (>= 4.2)
|
6
|
-
activesupport (>= 4.2)
|
7
|
-
fast_jsonapi (~> 1.5)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
actioncable (6.0.2.1)
|
13
|
-
actionpack (= 6.0.2.1)
|
14
|
-
nio4r (~> 2.0)
|
15
|
-
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (6.0.2.1)
|
17
|
-
actionpack (= 6.0.2.1)
|
18
|
-
activejob (= 6.0.2.1)
|
19
|
-
activerecord (= 6.0.2.1)
|
20
|
-
activestorage (= 6.0.2.1)
|
21
|
-
activesupport (= 6.0.2.1)
|
22
|
-
mail (>= 2.7.1)
|
23
|
-
actionmailer (6.0.2.1)
|
24
|
-
actionpack (= 6.0.2.1)
|
25
|
-
actionview (= 6.0.2.1)
|
26
|
-
activejob (= 6.0.2.1)
|
27
|
-
mail (~> 2.5, >= 2.5.4)
|
28
|
-
rails-dom-testing (~> 2.0)
|
29
|
-
actionpack (6.0.2.1)
|
30
|
-
actionview (= 6.0.2.1)
|
31
|
-
activesupport (= 6.0.2.1)
|
32
|
-
rack (~> 2.0, >= 2.0.8)
|
33
|
-
rack-test (>= 0.6.3)
|
34
|
-
rails-dom-testing (~> 2.0)
|
35
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
-
actiontext (6.0.2.1)
|
37
|
-
actionpack (= 6.0.2.1)
|
38
|
-
activerecord (= 6.0.2.1)
|
39
|
-
activestorage (= 6.0.2.1)
|
40
|
-
activesupport (= 6.0.2.1)
|
41
|
-
nokogiri (>= 1.8.5)
|
42
|
-
actionview (6.0.2.1)
|
43
|
-
activesupport (= 6.0.2.1)
|
44
|
-
builder (~> 3.1)
|
45
|
-
erubi (~> 1.4)
|
46
|
-
rails-dom-testing (~> 2.0)
|
47
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
-
activejob (6.0.2.1)
|
49
|
-
activesupport (= 6.0.2.1)
|
50
|
-
globalid (>= 0.3.6)
|
51
|
-
activemodel (6.0.2.1)
|
52
|
-
activesupport (= 6.0.2.1)
|
53
|
-
activerecord (6.0.2.1)
|
54
|
-
activemodel (= 6.0.2.1)
|
55
|
-
activesupport (= 6.0.2.1)
|
56
|
-
activestorage (6.0.2.1)
|
57
|
-
actionpack (= 6.0.2.1)
|
58
|
-
activejob (= 6.0.2.1)
|
59
|
-
activerecord (= 6.0.2.1)
|
60
|
-
marcel (~> 0.3.1)
|
61
|
-
activesupport (6.0.2.1)
|
62
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
63
|
-
i18n (>= 0.7, < 2)
|
64
|
-
minitest (~> 5.1)
|
65
|
-
tzinfo (~> 1.1)
|
66
|
-
zeitwerk (~> 2.2)
|
67
|
-
builder (3.2.4)
|
68
|
-
byebug (11.0.1)
|
69
|
-
coderay (1.1.2)
|
70
|
-
concurrent-ruby (1.1.5)
|
71
|
-
crass (1.0.5)
|
72
|
-
diff-lcs (1.3)
|
73
|
-
erubi (1.9.0)
|
74
|
-
factory_bot (5.1.1)
|
75
|
-
activesupport (>= 4.2.0)
|
76
|
-
factory_bot_rails (5.1.1)
|
77
|
-
factory_bot (~> 5.1.0)
|
78
|
-
railties (>= 4.2.0)
|
79
|
-
faker (2.9.0)
|
80
|
-
i18n (>= 1.6, < 1.8)
|
81
|
-
fast_jsonapi (1.5)
|
82
|
-
activesupport (>= 4.2)
|
83
|
-
globalid (0.4.2)
|
84
|
-
activesupport (>= 4.2.0)
|
85
|
-
i18n (1.7.0)
|
86
|
-
concurrent-ruby (~> 1.0)
|
87
|
-
loofah (2.4.0)
|
88
|
-
crass (~> 1.0.2)
|
89
|
-
nokogiri (>= 1.5.9)
|
90
|
-
mail (2.7.1)
|
91
|
-
mini_mime (>= 0.1.1)
|
92
|
-
marcel (0.3.3)
|
93
|
-
mimemagic (~> 0.3.2)
|
94
|
-
method_source (0.9.2)
|
95
|
-
mimemagic (0.3.3)
|
96
|
-
mini_mime (1.0.2)
|
97
|
-
mini_portile2 (2.4.0)
|
98
|
-
minitest (5.13.0)
|
99
|
-
nio4r (2.5.2)
|
100
|
-
nokogiri (1.10.7)
|
101
|
-
mini_portile2 (~> 2.4.0)
|
102
|
-
pry (0.12.2)
|
103
|
-
coderay (~> 1.1.0)
|
104
|
-
method_source (~> 0.9.0)
|
105
|
-
pry-byebug (3.7.0)
|
106
|
-
byebug (~> 11.0)
|
107
|
-
pry (~> 0.10)
|
108
|
-
rack (2.0.8)
|
109
|
-
rack-test (1.1.0)
|
110
|
-
rack (>= 1.0, < 3)
|
111
|
-
rails (6.0.2.1)
|
112
|
-
actioncable (= 6.0.2.1)
|
113
|
-
actionmailbox (= 6.0.2.1)
|
114
|
-
actionmailer (= 6.0.2.1)
|
115
|
-
actionpack (= 6.0.2.1)
|
116
|
-
actiontext (= 6.0.2.1)
|
117
|
-
actionview (= 6.0.2.1)
|
118
|
-
activejob (= 6.0.2.1)
|
119
|
-
activemodel (= 6.0.2.1)
|
120
|
-
activerecord (= 6.0.2.1)
|
121
|
-
activestorage (= 6.0.2.1)
|
122
|
-
activesupport (= 6.0.2.1)
|
123
|
-
bundler (>= 1.3.0)
|
124
|
-
railties (= 6.0.2.1)
|
125
|
-
sprockets-rails (>= 2.0.0)
|
126
|
-
rails-controller-testing (1.0.4)
|
127
|
-
actionpack (>= 5.0.1.x)
|
128
|
-
actionview (>= 5.0.1.x)
|
129
|
-
activesupport (>= 5.0.1.x)
|
130
|
-
rails-dom-testing (2.0.3)
|
131
|
-
activesupport (>= 4.2.0)
|
132
|
-
nokogiri (>= 1.6)
|
133
|
-
rails-html-sanitizer (1.3.0)
|
134
|
-
loofah (~> 2.3)
|
135
|
-
railties (6.0.2.1)
|
136
|
-
actionpack (= 6.0.2.1)
|
137
|
-
activesupport (= 6.0.2.1)
|
138
|
-
method_source
|
139
|
-
rake (>= 0.8.7)
|
140
|
-
thor (>= 0.20.3, < 2.0)
|
141
|
-
rake (10.5.0)
|
142
|
-
rspec-core (3.9.0)
|
143
|
-
rspec-support (~> 3.9.0)
|
144
|
-
rspec-expectations (3.9.0)
|
145
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
146
|
-
rspec-support (~> 3.9.0)
|
147
|
-
rspec-mocks (3.9.0)
|
148
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
149
|
-
rspec-support (~> 3.9.0)
|
150
|
-
rspec-rails (3.9.0)
|
151
|
-
actionpack (>= 3.0)
|
152
|
-
activesupport (>= 3.0)
|
153
|
-
railties (>= 3.0)
|
154
|
-
rspec-core (~> 3.9.0)
|
155
|
-
rspec-expectations (~> 3.9.0)
|
156
|
-
rspec-mocks (~> 3.9.0)
|
157
|
-
rspec-support (~> 3.9.0)
|
158
|
-
rspec-support (3.9.0)
|
159
|
-
sprockets (4.0.0)
|
160
|
-
concurrent-ruby (~> 1.0)
|
161
|
-
rack (> 1, < 3)
|
162
|
-
sprockets-rails (3.2.1)
|
163
|
-
actionpack (>= 4.0)
|
164
|
-
activesupport (>= 4.0)
|
165
|
-
sprockets (>= 3.0.0)
|
166
|
-
sqlite3 (1.4.2)
|
167
|
-
thor (1.0.1)
|
168
|
-
thread_safe (0.3.6)
|
169
|
-
tzinfo (1.2.5)
|
170
|
-
thread_safe (~> 0.1)
|
171
|
-
websocket-driver (0.7.1)
|
172
|
-
websocket-extensions (>= 0.1.0)
|
173
|
-
websocket-extensions (0.1.4)
|
174
|
-
zeitwerk (2.2.2)
|
175
|
-
|
176
|
-
PLATFORMS
|
177
|
-
ruby
|
178
|
-
|
179
|
-
DEPENDENCIES
|
180
|
-
bundler (~> 2.0)
|
181
|
-
factory_bot_rails
|
182
|
-
faker
|
183
|
-
json_apiable!
|
184
|
-
pry
|
185
|
-
pry-byebug
|
186
|
-
rails
|
187
|
-
rails-controller-testing
|
188
|
-
rake (~> 10.0)
|
189
|
-
rspec-rails (~> 3.9)
|
190
|
-
sqlite3
|
191
|
-
|
192
|
-
BUNDLED WITH
|
193
|
-
2.1.1
|