json_api_client 1.9.0 → 1.10.0

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
  SHA1:
3
- metadata.gz: 26efa266b2d3eb7d2b504738b19392474c832b02
4
- data.tar.gz: 5b60463dae1806e7318298cbd58ab5ce968453ae
3
+ metadata.gz: 8dc5a38f2bde33b9912837c82fa1fe5c9ef41c80
4
+ data.tar.gz: e8a926c76a1198ec9cf720fae46335e12f2c54fc
5
5
  SHA512:
6
- metadata.gz: 5830accd29e4821e85a32c0d39e650cc6603882a0022f9fe8cb633ec60c3efc030cc36d6d11d931ffd10cf38b4272ff3bac3184ca1547f81fe53b8071f92bbec
7
- data.tar.gz: 487d5411c3f399a737b72c0ff007076f71e92ab84b93fca19a9d3e54f9b345082358e9b98340ed7a5bfdd543f994ee4bac5be37759ace8ded75d74824b177e21
6
+ metadata.gz: 5d346d1b746c28b381e77a5842403808377f924feacce7d57f5f8d7ce9df4e9ccff8312a39e2313c0babc31965860e0af3c1b66648df60923af35cd2148467ad
7
+ data.tar.gz: 1951d5ea9ff1879cebd7f1c1fbafd25f752e2adbbdfd2f636231b23e4d16e8c282def341a5a368f282f64308c596388dc1a2eb58676bec90f3677254100aa006
@@ -21,6 +21,13 @@ module JsonApiClient
21
21
  def from_result_set(result_set)
22
22
  result_set.to_a
23
23
  end
24
+
25
+ def load_records(data)
26
+ data.map do |d|
27
+ record_class = Utils.compute_type(klass, d["type"].classify)
28
+ record_class.load id: d["id"]
29
+ end
30
+ end
24
31
  end
25
32
  end
26
33
  end
@@ -5,7 +5,12 @@ module JsonApiClient
5
5
  def from_result_set(result_set)
6
6
  result_set.first
7
7
  end
8
+
9
+ def load_records(data)
10
+ record_class = Utils.compute_type(klass, data["type"].classify)
11
+ record_class.load id: data["id"]
12
+ end
8
13
  end
9
14
  end
10
15
  end
11
- end
16
+ end
@@ -537,7 +537,11 @@ module JsonApiClient
537
537
  def relationship_data_for(name, relationship_definition)
538
538
  # look in included data
539
539
  if relationship_definition.key?("data")
540
- return included_data_for(name, relationship_definition)
540
+ if relationships.attribute_changed?(name)
541
+ return relation_objects_for(name, relationship_definition)
542
+ else
543
+ return included_data_for(name, relationship_definition)
544
+ end
541
545
  end
542
546
 
543
547
  url = relationship_definition["links"]["related"]
@@ -548,6 +552,13 @@ module JsonApiClient
548
552
  nil
549
553
  end
550
554
 
555
+ def relation_objects_for(name, relationship_definition)
556
+ data = relationship_definition["data"]
557
+ assoc = association_for(name)
558
+ return if data.nil? || assoc.nil?
559
+ assoc.load_records(data)
560
+ end
561
+
551
562
  def method_missing(method, *args)
552
563
  relationship_definition = relationship_definition_for(method)
553
564
 
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.9.0"
2
+ VERSION = "1.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport