para 0.12.6 → 0.12.7

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
  SHA256:
3
- metadata.gz: 54ef941e16858159844a9edfc2d38bf45205c54b0de05a9138db4db9b55f9cd9
4
- data.tar.gz: a3119a93739b8f5590984e0e78279258d580be453a39e880446ec9026c5f4783
3
+ metadata.gz: 5339b2dc5c28403fd3e4ba08fbb1bfc7b2b2196269f9927d25eb1d428eb99d71
4
+ data.tar.gz: 6266de04143dbd8e18aa9826e8a007d2d96909d4d4f6d9704791e30893f0cffe
5
5
  SHA512:
6
- metadata.gz: a81dade0932df9173846f0d9ea7750def8140f1f2b62c88b0d5098d67cb59b05bf26053d0cc1902bcaca9743eba7b278ce472d923406e620ae3679302035302e
7
- data.tar.gz: 657bef4b4cf573e663459e548bc1b198d621e517a4178f6acf3aea3520ecba5ea19b5f871561657ca704d7cb3b63cedefb228b82e280b3e422db68b0d549ea71
6
+ metadata.gz: aa7cfd1587567f56a06853bfc0acf74736d4082d79a59f51af90de4fc4afc4fc840085e1e4580aa8372eee4e6e2299584f262ba7d064ee47fffc4abf71ed6fd9
7
+ data.tar.gz: 5ad58a35c8f690c2ce70063f12cc04ebf0f2e1b812ea22c8f2918193f16e3b7f98a4758b0a780affbb3e7e72a4f319906dae122c650bd3c183aba84ac2a4db14
@@ -97,10 +97,7 @@ module Para
97
97
  # This is not the most optimized solution, but works well enough as if the
98
98
  # author's posts match previously cloned posts, they won't be cloned as they'll
99
99
  # exist in the cloned resources dictionary.
100
- next if path.length >= 4 &&
101
- path[-4] == path[-2] &&
102
- path[-2] == reflection_name &&
103
- path[-3] == path[-1]
100
+ next if circular_reference?(path, reflection_name)
104
101
 
105
102
  hash[reflection_name] = {}
106
103
 
@@ -140,6 +137,8 @@ module Para
140
137
  options = nested_resource.class.try(:cloneable_options)
141
138
  return reflection_options unless options
142
139
 
140
+ puts "Building cloneable options for #{nested_resource.class.name} at path #{path.join(' -> ')}"
141
+
143
142
  target_options = build_cloneable_options_tree(nested_resource, path)
144
143
  reflection_options.deep_merge!(target_options)
145
144
  end
@@ -191,6 +190,43 @@ module Para
191
190
 
192
191
  deep_relations.empty? ? shallow_relations : shallow_relations + [deep_relations]
193
192
  end
193
+
194
+ # Checks if adding reflection_name to the path would create a circular reference
195
+ # of 2 levels deep with a cycle length between 2 and 10.
196
+ #
197
+ # Examples of detected patterns:
198
+ #
199
+ # Length 2: [:a, :b, :a, :b]
200
+ # Length 3: [:a, :b, :c, :a, :b, :c]
201
+ # Length 4: [:a, :b, :c, :d, :a, :b, :c, :d]
202
+ #
203
+ def circular_reference?(path, reflection_name)
204
+ # Check for cycle lengths from 2 to 10
205
+ (2..10).each do |cycle_length|
206
+ # We need at least 2 * cycle_length elements in the path to detect a cycle
207
+ required_length = cycle_length * 2
208
+ next if path.length < required_length
209
+
210
+ # Check if the pattern repeats exactly twice
211
+ # The new reflection_name would be at position -cycle_length
212
+ match = true
213
+
214
+ # First, check if the element at -cycle_length position matches reflection_name
215
+ next unless path[-cycle_length] == reflection_name
216
+
217
+ # Then check if all other elements in the first cycle match the second cycle
218
+ (1...cycle_length).each do |offset|
219
+ if path[-(cycle_length + offset)] != path[-offset]
220
+ match = false
221
+ break
222
+ end
223
+ end
224
+
225
+ return true if match
226
+ end
227
+
228
+ false
229
+ end
194
230
  end
195
231
  end
196
232
  end
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.12.6'
4
+ VERSION = '0.12.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.6
4
+ version: 0.12.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
@@ -790,7 +790,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
790
790
  - !ruby/object:Gem::Version
791
791
  version: '0'
792
792
  requirements: []
793
- rubygems_version: 3.6.7
793
+ rubygems_version: 3.6.9
794
794
  specification_version: 4
795
795
  summary: Rails admin engine
796
796
  test_files: []