graphiti 1.0.rc.17 → 1.0.rc.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti/errors.rb +1 -1
- data/lib/graphiti/resource.rb +2 -2
- data/lib/graphiti/util/persistence.rb +22 -5
- data/lib/graphiti/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: afaf92e3ca234c7c84974f05ebd8feae5b532fe0
|
4
|
+
data.tar.gz: ad2985a29b2601440f52d86d5458d70f736a5ff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06cada17b7a5d38dbe04cfccf481b5a52c1218fe87fb04cd665e35ee777c0c726484467173367e5b375d9f42626526c4627875a1eec7533c4e63628d4d4f5305
|
7
|
+
data.tar.gz: b4b7ba5cbce5c57e45b5789e3e36cff0467b62ae0208b6dfadee59ad95b98ab9ff498be68816e6404bb9d0772fd0d411bed129b7785cf3b14507853fda6c0771
|
data/lib/graphiti/errors.rb
CHANGED
@@ -94,7 +94,7 @@ The adapter #{@adapter.class} does not implement method '#{@method}', which was
|
|
94
94
|
|
95
95
|
def message
|
96
96
|
<<-MSG
|
97
|
-
#{@resource.class}: Tried to persist
|
97
|
+
#{@resource.class}: Tried to persist association #{@sideload.name.inspect} but marked writable: false
|
98
98
|
MSG
|
99
99
|
end
|
100
100
|
end
|
data/lib/graphiti/resource.rb
CHANGED
@@ -94,9 +94,9 @@ module Graphiti
|
|
94
94
|
adapter.disassociate(parent, child, association_name, type)
|
95
95
|
end
|
96
96
|
|
97
|
-
def persist_with_relationships(meta, attributes, relationships, caller_model = nil)
|
97
|
+
def persist_with_relationships(meta, attributes, relationships, caller_model = nil, foreign_key = nil)
|
98
98
|
persistence = Graphiti::Util::Persistence \
|
99
|
-
.new(self, meta, attributes, relationships, caller_model)
|
99
|
+
.new(self, meta, attributes, relationships, caller_model, foreign_key)
|
100
100
|
persistence.run
|
101
101
|
end
|
102
102
|
|
@@ -5,12 +5,15 @@ class Graphiti::Util::Persistence
|
|
5
5
|
# @param [Hash] meta see (Deserializer#meta)
|
6
6
|
# @param [Hash] attributes see (Deserializer#attributes)
|
7
7
|
# @param [Hash] relationships see (Deserializer#relationships)
|
8
|
-
|
8
|
+
# @param [Model] caller_model The persisted parent object in the request graph
|
9
|
+
# @param [Symbol] foreign_key Attribute assigned by parent object in graph
|
10
|
+
def initialize(resource, meta, attributes, relationships, caller_model, foreign_key = nil)
|
9
11
|
@resource = resource
|
10
12
|
@meta = meta
|
11
13
|
@attributes = attributes
|
12
14
|
@relationships = relationships
|
13
15
|
@caller_model = caller_model
|
16
|
+
@foreign_key = foreign_key
|
14
17
|
|
15
18
|
# Find the correct child resource for a given jsonapi type
|
16
19
|
if meta_type = @meta[:type].try(:to_sym)
|
@@ -19,9 +22,7 @@ class Graphiti::Util::Persistence
|
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
@attributes[key] = @resource.typecast(key, value, :writable)
|
24
|
-
end
|
25
|
+
typecast_attributes
|
25
26
|
end
|
26
27
|
|
27
28
|
# Perform the actual save logic.
|
@@ -68,6 +69,20 @@ class Graphiti::Util::Persistence
|
|
68
69
|
|
69
70
|
private
|
70
71
|
|
72
|
+
# In the case where we're sideposting in order to associate 2 nodes
|
73
|
+
# in the graph, the foreign key gets merged into the child's attributes
|
74
|
+
# This attribute should *not* need to be marked writable, as that
|
75
|
+
# would allow writing as a straight attribute instead of just an association
|
76
|
+
def typecast_attributes
|
77
|
+
@attributes.each_pair do |key, value|
|
78
|
+
if @foreign_key == key
|
79
|
+
@attributes[key] = value
|
80
|
+
else
|
81
|
+
@attributes[key] = @resource.typecast(key, value, :writable)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
71
86
|
def add_hook(prc)
|
72
87
|
::Graphiti::Util::Hooks.add(prc)
|
73
88
|
end
|
@@ -170,7 +185,9 @@ class Graphiti::Util::Persistence
|
|
170
185
|
|
171
186
|
if x[:sideload].writable?
|
172
187
|
x[:object] = x[:resource]
|
173
|
-
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships], caller_model)
|
188
|
+
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships], caller_model, x[:foreign_key])
|
189
|
+
else
|
190
|
+
raise Graphiti::Errors::UnwritableRelationship.new(@resource, x[:sideload])
|
174
191
|
end
|
175
192
|
|
176
193
|
processed << x
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.rc.
|
4
|
+
version: 1.0.rc.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|