jsonapi_compliable 0.6.3 → 0.6.4

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: 9138437a5f6cf6613987e8f84a8822d1cf2c84e4
4
- data.tar.gz: 16ac6bf944f5f04e3573fd8e033a90d83658a97d
3
+ metadata.gz: 581276bd4edc803209be48bec1f03a72ffad2bd4
4
+ data.tar.gz: bda4a188aaecfab0a92b7f5bd70c45b5d7265420
5
5
  SHA512:
6
- metadata.gz: e5eb95f420f9811808b528d5e73e40e8f0279e829d307aaaeda6d1127fe3e99d897ce63d56a47b8e3a6ee3b3b25a902d51af68c7bd4a7c7e57a3744a3b721423
7
- data.tar.gz: d2cb8c48650ca2c1be14683e0bef55f354153efe7d7189d3803d521dd7f22befc34cda32f027810330358e6c81c219d7d401e4382343e2d3b06886601ba00c86
6
+ metadata.gz: 341611451bd572895934709477ec7e974a47d7f5dd6decdb00a70b9ce724ed70b2a7ca0552f0be9e4a6afad91d94faff38c608f960ceb009587bd8a75c524e4e
7
+ data.tar.gz: 5870888b34b6caf62018c6ef69c7703c074126c6cf339ba49173cfe31b64eda2d930cf3bcd0da7906ec660949bfc091e8d0b924fcfe89ed4679af0268d5f18ea
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- jsonapi_compliable (0.6.1)
4
+ jsonapi_compliable (0.6.3)
5
5
  jsonapi-serializable (~> 0.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- jsonapi_compliable (0.6.1)
4
+ jsonapi_compliable (0.6.3)
5
5
  jsonapi-serializable (~> 0.1)
6
6
 
7
7
  GEM
@@ -75,36 +75,32 @@ module JsonapiCompliable
75
75
  end
76
76
 
77
77
  # Grab from nested sideloads, AND resource, recursively
78
- # To prevent circular relationships (author resource sideloads
79
- # books and books resource sideloads authors), this allows
80
- # sideloading up to 10 levels deep into the nesting of relationships
81
- # We may want to make this configurable (possible at runtime), or
82
- # maybe there is a better pattern here
83
- def to_hash(levels_deep = 0)
84
- levels_deep += 1
85
- return {} if levels_deep == 10
86
-
87
- { name => {} }.tap do |hash|
78
+ def to_hash(processed = [])
79
+ return { name => {} } if processed.include?(self)
80
+ processed << self
81
+
82
+ result = { name => {} }.tap do |hash|
88
83
  @sideloads.each_pair do |key, sideload|
89
- hash[name][key] = sideload.to_hash(levels_deep)[key] || {}
84
+ hash[name][key] = sideload.to_hash(processed)[key] || {}
90
85
 
91
86
  if sideload.polymorphic?
92
87
  sideload.polymorphic_groups.each_pair do |type, sl|
93
- hash[name][key].merge!(nested_sideload_hash(sl, levels_deep))
88
+ hash[name][key].merge!(nested_sideload_hash(sl, processed))
94
89
  end
95
90
  else
96
- hash[name][key].merge!(nested_sideload_hash(sideload, levels_deep))
91
+ hash[name][key].merge!(nested_sideload_hash(sideload, processed))
97
92
  end
98
93
  end
99
94
  end
95
+ result
100
96
  end
101
97
 
102
98
  private
103
99
 
104
- def nested_sideload_hash(sideload, levels_deep)
100
+ def nested_sideload_hash(sideload, processed)
105
101
  {}.tap do |hash|
106
102
  if sideloading = sideload.resource_class.sideloading
107
- hash.merge!(sideloading.to_hash(levels_deep)[:base])
103
+ hash.merge!(sideloading.to_hash(processed)[:base])
108
104
  end
109
105
  end
110
106
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  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.3
4
+ version: 0.6.4
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-25 00:00:00.000000000 Z
12
+ date: 2017-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable