json_api_client 1.12.0 → 1.12.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
- SHA1:
3
- metadata.gz: 3cfb32875fc8446747a7d25e363af32fcd2b7667
4
- data.tar.gz: '0178c432e6547f8d542d05f138b0b80642cdb724'
2
+ SHA256:
3
+ metadata.gz: e2ec83cd51f34ee34e32551913d01f9e9c9aa7d115ef475f75900aac7fceee2c
4
+ data.tar.gz: '0193065a70ff9f0b9f05f4c3205f702ebdc559e6fd3de48296a50d2c069261e1'
5
5
  SHA512:
6
- metadata.gz: 60f9e5bb268999432abfb9253384dcc75d2fa8ba7321324ec2a55a8003f94c7241ffd08c8cfbe3ca6120f8a7a78c059e5a95fb3d15b7823cbb60686a52729259
7
- data.tar.gz: 5c7540a4f1d9d43be2c55864d5483155c1b89ff543ab005a8ecea749b5c9cd591755f5d795ad9e1bcee7e0454eabdb377b1f6298605ba628b7c3aee14a8cc6a2
6
+ metadata.gz: 7f72be97a49f8a922350f048147791696e333aa9e970d98a5640604843af3c5b6b500994db80ba47e9f968f51be80398585408c5802f984346531e455dbd8fb9
7
+ data.tar.gz: 04cbe2ac54b543c0fb22f3fdfc59cf838bcec1dbc5fb4f927399f308dba57f1a907a6992a1329e4d6bb72eaaaab8ae629714c497cab5d323e3425197ddb663f5
@@ -4,20 +4,30 @@ module JsonApiClient
4
4
 
5
5
  def initialize(result_set, data)
6
6
  record_class = result_set.record_class
7
- included_set = data.map do |datum|
8
- type = datum["type"]
7
+ grouped_data = data.group_by{|datum| datum["type"]}
8
+ grouped_included_set = grouped_data.each_with_object({}) do |(type, records), h|
9
9
  klass = Utils.compute_type(record_class, record_class.key_formatter.unformat(type).singularize.classify)
10
- params = klass.parser.parameters_from_resource(datum)
11
- resource = klass.load(params)
12
- resource.last_result_set = result_set
13
- resource
10
+ h[type] = records.map do |record|
11
+ params = klass.parser.parameters_from_resource(record)
12
+ klass.load(params).tap do |resource|
13
+ resource.last_result_set = result_set
14
+ end
15
+ end
14
16
  end
15
17
 
16
- included_set.concat(result_set) if record_class.search_included_in_result_set
17
- @data = included_set.group_by(&:type).inject({}) do |h, (type, resources)|
18
- h[type] = resources.index_by(&:id)
19
- h
18
+ if record_class.search_included_in_result_set
19
+ # deep_merge overrides the nested Arrays o_O
20
+ # {a: [1,2]}.deep_merge(a: [3,4]) # => {a: [3,4]}
21
+ grouped_included_set.merge!(result_set.group_by(&:type)) do |_, resources1, resources2|
22
+ resources1 + resources2
23
+ end
20
24
  end
25
+
26
+ grouped_included_set.each do |type, resources|
27
+ grouped_included_set[type] = resources.index_by(&:id)
28
+ end
29
+
30
+ @data = grouped_included_set
21
31
  end
22
32
 
23
33
  def data_for(method_name, definition)
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.12.0"
2
+ VERSION = "1.12.1"
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.12.0
4
+ version: 1.12.1
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-06-11 00:00:00.000000000 Z
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -198,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.6.14.3
201
+ rubygems_version: 3.0.3
203
202
  signing_key:
204
203
  specification_version: 4
205
204
  summary: Build client libraries compliant with specification defined by jsonapi.org