graphiti 1.0.rc.17 → 1.0.rc.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b8be3f292174af6955e7e7d07680dea6a6c17c7
4
- data.tar.gz: 265d4c776f7804139ffc52f7b1bba30c6a858f34
3
+ metadata.gz: afaf92e3ca234c7c84974f05ebd8feae5b532fe0
4
+ data.tar.gz: ad2985a29b2601440f52d86d5458d70f736a5ff5
5
5
  SHA512:
6
- metadata.gz: e840ed2899472615ce1fb032eecf7e84a1aa9c1395c4a196badd9282aa1e7c53e21d9f84be72879b8c9497eeec4a78672c083010f60fc9b79d33d5f86c8dfa2e
7
- data.tar.gz: 1852b8a6ac1e2a3ae3d3c360547b566b43ef33fc57a47ed5434ac1eb2621e492415e1948e6eb571abd83658c8845f45669c7b0f2120480a6b9809bfcaa1b982f
6
+ metadata.gz: 06cada17b7a5d38dbe04cfccf481b5a52c1218fe87fb04cd665e35ee777c0c726484467173367e5b375d9f42626526c4627875a1eec7533c4e63628d4d4f5305
7
+ data.tar.gz: b4b7ba5cbce5c57e45b5789e3e36cff0467b62ae0208b6dfadee59ad95b98ab9ff498be68816e6404bb9d0772fd0d411bed129b7785cf3b14507853fda6c0771
@@ -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 sideload #{@sideload.name.inspect} but marked writable: false
97
+ #{@resource.class}: Tried to persist association #{@sideload.name.inspect} but marked writable: false
98
98
  MSG
99
99
  end
100
100
  end
@@ -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
- def initialize(resource, meta, attributes, relationships, caller_model)
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
- @attributes.each_pair do |key, value|
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
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.rc.17"
2
+ VERSION = "1.0.rc.18"
3
3
  end
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.17
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-14 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable