json_apiable 0.4.1 → 0.6.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
  SHA256:
3
- metadata.gz: d7f8ca1f3bf0021a5b326f69c09fa891813c63da56824acafb67f5edf22b8cc6
4
- data.tar.gz: 13c3c4b1e542b688241eaf73be98e35d35c0d712ce552d77243cf958fdce3d34
3
+ metadata.gz: f5b2c74a3a6c4e7fa672f50fa0ed5dea35202d4909ee03cd1095a982738c8739
4
+ data.tar.gz: f87e9f25265bb784e4e977bc70d1531ddab109a3211139b1a0112c13f67c890f
5
5
  SHA512:
6
- metadata.gz: 941b661ae943c9e6b5344be482740356f78ee75393ed334ddf97516ba5f08bc821252ae34fa3d33d2142366b779095aebe7f8e8600280ffa9ce22acb3eded9a1
7
- data.tar.gz: 66f37012eb785a178d5dd2c14979f3296f3818c8b86f940c33b1d6269fa8b5350a1dab1de9993e61c366f98251542870afe66f5ed42bcd56569951ecd3c3395c
6
+ metadata.gz: 68fbc75bb6849ca3e9c4f69f9ae18b9c1ee3fbcf8413acac08de082acf4a5d60a4f6171114a8adffec0ff3b228053ea0d278d222580d248d2a23e8564b6c850a
7
+ data.tar.gz: 6a271d8688964a79967d694a08d4b73d040c1159c5b30b9acf7f160271a3210489d93ccd475f02876038736d7fab0fc4d34efa21acdcd6afbfcd985e1e9a97b3
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ Changelog
2
+ =========
3
+ ## 0.6.1 06/02/2021
4
+ * Adding not_blank_matcher to filter-matchers
5
+
6
+ ## 0.6.0 05/15/2021
7
+ * Adding support for "has_many" nested attributes
8
+ * Updating specs
9
+
10
+ ## 0.5.2 05/06/2021
11
+ * Updating dependency gems
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', '>= 4.2'
28
- spec.add_dependency 'activesupport', '>= 4.2'
29
- spec.add_dependency 'fast_jsonapi', '~> 1.5'
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'
@@ -10,15 +10,19 @@ module JsonApiable
10
10
 
11
11
  module_function :matches?
12
12
 
13
+ def not_blank_matcher
14
+ proc do |value|
15
+ handle_error(value) do
16
+ value.present?
17
+ end
18
+ end
19
+ end
20
+
13
21
  # returns true for boolean values, false for any other
14
22
  def boolean_matcher
15
23
  proc do |value|
16
24
  handle_error(value) do
17
- if true_matcher.call(value) || (value == false || value =~ /^(false|f|0)$/i)
18
- true
19
- else
20
- false
21
- end
25
+ true_matcher.call(value) || (value == false || value =~ /^(false|f|0)$/i)
22
26
  end
23
27
  end
24
28
  end
@@ -27,11 +31,7 @@ module JsonApiable
27
31
  def true_matcher
28
32
  proc do |value|
29
33
  handle_error(value) do
30
- if value == true || value =~ /^(true|t|1)$/i
31
- true
32
- else
33
- false
34
- end
34
+ value == true || value =~ /^(true|t|1)$/i
35
35
  end
36
36
  end
37
37
  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
@@ -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 = value.is_a?(ActionController::Parameters) ? "#{key}_attributes" : 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiable
4
- VERSION = "0.4.1"
4
+ VERSION = "0.6.1"
5
5
  end
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: 0.4.1
4
+ version: 0.6.1
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: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2021-06-02 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: '4.2'
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: '4.2'
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: '4.2'
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: '4.2'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: fast_jsonapi
42
+ name: jsonapi-serializer
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
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: '1.5'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  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.0.6
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.1.1)
69
- coderay (1.1.2)
70
- concurrent-ruby (1.1.6)
71
- crass (1.0.6)
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.10.2)
80
- i18n (>= 1.6, < 2)
81
- fast_jsonapi (1.5)
82
- activesupport (>= 4.2)
83
- globalid (0.4.2)
84
- activesupport (>= 4.2.0)
85
- i18n (1.8.3)
86
- concurrent-ruby (~> 1.0)
87
- loofah (2.6.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.5)
96
- mini_mime (1.0.2)
97
- mini_portile2 (2.4.0)
98
- minitest (5.14.1)
99
- nio4r (2.5.2)
100
- nokogiri (1.10.9)
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.8.0)
106
- byebug (~> 11.0)
107
- pry (~> 0.10)
108
- rack (2.2.3)
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 (13.0.1)
142
- rspec-core (3.9.1)
143
- rspec-support (~> 3.9.1)
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.1)
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.2)
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.7)
170
- thread_safe (~> 0.1)
171
- websocket-driver (0.7.1)
172
- websocket-extensions (>= 0.1.0)
173
- websocket-extensions (0.1.5)
174
- zeitwerk (2.3.0)
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 (~> 13.0)
189
- rspec-rails (~> 3.9)
190
- sqlite3
191
-
192
- BUNDLED WITH
193
- 2.1.1