jsonapi_compliable 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jsonapi_compliable.rb +1 -0
- data/lib/jsonapi_compliable/adapters/active_record.rb +1 -1
- data/lib/jsonapi_compliable/base.rb +13 -4
- data/lib/jsonapi_compliable/errors.rb +1 -0
- data/lib/jsonapi_compliable/extensions/temp_id.rb +15 -0
- data/lib/jsonapi_compliable/resource.rb +7 -2
- data/lib/jsonapi_compliable/util/validation_response.rb +31 -5
- data/lib/jsonapi_compliable/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9138437a5f6cf6613987e8f84a8822d1cf2c84e4
|
4
|
+
data.tar.gz: 16ac6bf944f5f04e3573fd8e033a90d83658a97d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5eb95f420f9811808b528d5e73e40e8f0279e829d307aaaeda6d1127fe3e99d897ce63d56a47b8e3a6ee3b3b25a902d51af68c7bd4a7c7e57a3744a3b721423
|
7
|
+
data.tar.gz: d2cb8c48650ca2c1be14683e0bef55f354153efe7d7189d3803d521dd7f22befc34cda32f027810330358e6c81c219d7d401e4382343e2d3b06886601ba00c86
|
data/lib/jsonapi_compliable.rb
CHANGED
@@ -48,23 +48,32 @@ module JsonapiCompliable
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def jsonapi_create
|
51
|
-
|
51
|
+
_persist do
|
52
52
|
resource.persist_with_relationships \
|
53
53
|
deserialized_params.meta,
|
54
54
|
deserialized_params.attributes,
|
55
55
|
deserialized_params.relationships
|
56
56
|
end
|
57
|
-
Util::ValidationResponse.new(created, deserialized_params)
|
58
57
|
end
|
59
58
|
|
60
59
|
def jsonapi_update
|
61
|
-
|
60
|
+
_persist do
|
62
61
|
resource.persist_with_relationships \
|
63
62
|
deserialized_params.meta,
|
64
63
|
deserialized_params.attributes,
|
65
64
|
deserialized_params.relationships
|
66
65
|
end
|
67
|
-
|
66
|
+
end
|
67
|
+
|
68
|
+
def _persist
|
69
|
+
validation_response = nil
|
70
|
+
resource.transaction do
|
71
|
+
object = yield
|
72
|
+
validation_response = Util::ValidationResponse.new \
|
73
|
+
object, deserialized_params
|
74
|
+
raise Errors::ValidationError unless validation_response.to_a[1]
|
75
|
+
end
|
76
|
+
validation_response
|
68
77
|
end
|
69
78
|
|
70
79
|
def perform_render_jsonapi(opts)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module JsonapiCompliable
|
2
|
+
module SerializableTempId
|
3
|
+
def as_jsonapi(*)
|
4
|
+
super.tap do |hash|
|
5
|
+
if temp_id = @object.instance_variable_get(:'@_jsonapi_temp_id')
|
6
|
+
hash[:'temp-id'] = temp_id
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
JSONAPI::Serializable::Resource.class_eval do
|
14
|
+
prepend JsonapiCompliable::SerializableTempId
|
15
|
+
end
|
@@ -226,9 +226,14 @@ module JsonapiCompliable
|
|
226
226
|
end
|
227
227
|
|
228
228
|
def transaction
|
229
|
-
|
230
|
-
|
229
|
+
response = nil
|
230
|
+
begin
|
231
|
+
adapter.transaction(model) do
|
232
|
+
response = yield
|
233
|
+
end
|
234
|
+
rescue Errors::ValidationError
|
231
235
|
end
|
236
|
+
response
|
232
237
|
end
|
233
238
|
end
|
234
239
|
end
|
@@ -7,14 +7,40 @@ class JsonapiCompliable::Util::ValidationResponse
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def success?
|
10
|
-
|
11
|
-
object.errors.blank?
|
12
|
-
else
|
13
|
-
true
|
14
|
-
end
|
10
|
+
all_valid?(object, @deserialized_params.relationships)
|
15
11
|
end
|
16
12
|
|
17
13
|
def to_a
|
18
14
|
[object, success?]
|
19
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def valid_object?(object)
|
20
|
+
object.respond_to?(:errors) && object.errors.blank?
|
21
|
+
end
|
22
|
+
|
23
|
+
def all_valid?(model, deserialized_params)
|
24
|
+
valid = true
|
25
|
+
return false unless valid_object?(model)
|
26
|
+
deserialized_params.each_pair do |name, payload|
|
27
|
+
if payload.is_a?(Array)
|
28
|
+
related_objects = model.send(name)
|
29
|
+
related_objects.each do |r|
|
30
|
+
valid = valid_object?(r)
|
31
|
+
|
32
|
+
if valid
|
33
|
+
valid = all_valid?(r, deserialized_params[:relationships] || {})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
related_object = model.send(name)
|
38
|
+
valid = valid_object?(related_object)
|
39
|
+
if valid
|
40
|
+
valid = all_valid?(related_object, deserialized_params[:relationships] || {})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
valid
|
45
|
+
end
|
20
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_compliable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-serializable
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/jsonapi_compliable/errors.rb
|
154
154
|
- lib/jsonapi_compliable/extensions/boolean_attribute.rb
|
155
155
|
- lib/jsonapi_compliable/extensions/extra_attribute.rb
|
156
|
+
- lib/jsonapi_compliable/extensions/temp_id.rb
|
156
157
|
- lib/jsonapi_compliable/query.rb
|
157
158
|
- lib/jsonapi_compliable/rails.rb
|
158
159
|
- lib/jsonapi_compliable/resource.rb
|
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
197
|
version: '0'
|
197
198
|
requirements: []
|
198
199
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.11
|
200
201
|
signing_key:
|
201
202
|
specification_version: 4
|
202
203
|
summary: Easily build jsonapi.org-compatible APIs
|