consyncful-tree 1.0.0 → 1.0.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
2
  SHA256:
3
- metadata.gz: 8f9dfd640ea20ac184288e3af655a3def80755429ca2d0880d3d05af4848bd3f
4
- data.tar.gz: e523aa66dcc6f005f661eb4bba23644f52b83b0a48d6fb0b6774ec631b760fc9
3
+ metadata.gz: de96606e91d4b2f832cb42429df45f2794cb07526ece0a98e7766384bfabb430
4
+ data.tar.gz: 32b4749935b9c503e1b6171f09a6b7fe92d1afaec510db1402dc7c377812be8c
5
5
  SHA512:
6
- metadata.gz: 3f68b3fef751d66d2e3ae02d4a21819fda521a1bbd3ae49bbc5a5c78eb81826ed37d5bc83a11c094ce232995d465443000fdca03585303be7dfcf6a7d40735ce
7
- data.tar.gz: 98a49750eb6a42057da56e97e92b36cce1ac9fb9d8618428b62fcc95232b3f4f52150cca265fde4bbf5376f88f8f0bffb4f58ca28ae829b6001faf43c010e3b6
6
+ metadata.gz: 4a8e3e4db80d8b746872e2809715e549def805ab0737bbb3e6d0989e3ea29f0a32428f11e2ddb984055d14d7a2d787eeef966383d8ecebd3a0a2df706f44aebf
7
+ data.tar.gz: 270dd99f798052d23b6372dc9602c395fe343ee00e9a2aee904a5ec09b731e86d97556d6ac23e179cb0c1651f57a012b2c143cca4d8fac962c34ff12e1c1420b
data/.rubocop.yml CHANGED
@@ -15,3 +15,8 @@ Layout/LineLength:
15
15
 
16
16
  Style/Documentation:
17
17
  Enabled: false
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - 'spec/**/*'
22
+ - 'consyncful-tree.gemspec'
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [1.0.0] - 2022-06-14
4
4
 
5
5
  - Initial release
6
+
7
+ ## [1.0.1] - 2022-06-20
8
+
9
+ - Fixed a bug in the break condition which caused infinite loops
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consyncful-tree (1.0.0)
4
+ consyncful-tree (1.0.1)
5
5
  consyncful (~> 0.7.0)
6
6
 
7
7
  GEM
@@ -24,19 +24,20 @@ module Consyncful
24
24
 
25
25
  next if key == "child_models" || child_ids.empty?
26
26
 
27
- child_ids + lookup_child_objects(child_ids)
27
+ child_objects = child_ids.map { |id| Consyncful::Base.where(id: id).first }
28
+
29
+ child_ids + lookup_child_model_ids_for_list(child_objects)
28
30
  end.flatten.compact
29
31
  end
30
32
 
31
- def lookup_child_objects(child_ids)
32
- return [] if child_ids.empty?
33
-
34
- child_ids.map do |id|
35
- obj = Consyncful::Base.where(id: id).first
33
+ def lookup_child_model_ids_for_list(child_objects)
34
+ return [] if child_objects.empty?
36
35
 
36
+ child_objects.map do |obj|
37
37
  next if obj.nil?
38
38
 
39
- lookup_child_model_ids(context: obj) if classes_with_parent_concern.exclude?(obj.class.to_s)
39
+ obj_is_parent = classes_with_parent_concern.include?(obj.class)
40
+ lookup_child_model_ids(context: obj) unless obj_is_parent
40
41
  end.flatten.compact
41
42
  end
42
43
 
@@ -52,6 +53,16 @@ module Consyncful
52
53
 
53
54
  private
54
55
 
56
+ # NOTE: I think this break condition is a bit odd.
57
+ # It works if we think about a "Parent" being a unit that's fields and dependencies will display on
58
+ # one page; if it isn't content we are going to display with the parent, then we don't care.
59
+ # It protects us from some kinds of cyclic depencencies.
60
+ #
61
+ # However, if we changed our recursive method to instead pass down the children that had been found so far and
62
+ # only check its children's children if they aren't in the list yet, then we'd be protected from all
63
+ # cyclic dependencies.
64
+ # I ran out of time to make that change.
65
+
55
66
  def classes_with_parent_concern
56
67
  # ObjectSpace lets you interact with garbage collection and traverse alive objects.
57
68
  # This will iterate through all the classes for objects that are alive.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Consyncful
4
4
  module Tree
5
- VERSION = "1.0.0"
5
+ VERSION = "1.0.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consyncful-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DigitalNZ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-14 00:00:00.000000000 Z
11
+ date: 2022-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler