hierarchable 0.3.0 → 0.3.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/hierarchable/hierarchable.rb +13 -9
- data/lib/hierarchable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77318268a18001072d590f7ad65524e5f608923cea6c6e757946ad164862518b
|
|
4
|
+
data.tar.gz: 7740d0be435b42dd701fc626eaa706b58c50688c0bb7639da9caf8b5864d3f3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '078378d734ddc00ccfcecf685fdd142e581560af7444a34985172c354eae1aeedb91ea98a2b08fd47a20728ce8d594c5d965a49409e7957236549b34352a852f'
|
|
7
|
+
data.tar.gz: 4b9192aec201abb47df5be7589a207c46131fb3544bb2b7cb439dd5c4d6a5df4fe09bc98e32aba14b72b2f3aa789295933226793cb282741a90f1dcd442f38ca
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -238,7 +238,7 @@ However there are times when we need to manually add a child relation to be insp
|
|
|
238
238
|
|
|
239
239
|
```ruby
|
|
240
240
|
class SomeObject
|
|
241
|
-
include
|
|
241
|
+
include Hierarchable
|
|
242
242
|
hierarched parent_source: :parent,
|
|
243
243
|
additional_descendant_associations: [:some_association]
|
|
244
244
|
end
|
|
@@ -248,7 +248,7 @@ There may also be a case when we want exact control over what associations that
|
|
|
248
248
|
|
|
249
249
|
```ruby
|
|
250
250
|
class SomeObject
|
|
251
|
-
include
|
|
251
|
+
include Hierarchable
|
|
252
252
|
hierarched parent_source: :parent,
|
|
253
253
|
descendant_associations: [:some_association]
|
|
254
254
|
end
|
|
@@ -396,6 +396,7 @@ module Hierarchable
|
|
|
396
396
|
until models_to_analyze.empty?
|
|
397
397
|
|
|
398
398
|
klass = models_to_analyze.pop
|
|
399
|
+
next unless klass
|
|
399
400
|
next if models.include?(klass)
|
|
400
401
|
|
|
401
402
|
obj = klass.new
|
|
@@ -514,7 +515,7 @@ module Hierarchable
|
|
|
514
515
|
# also add in the one provided.
|
|
515
516
|
#
|
|
516
517
|
# class A
|
|
517
|
-
# include
|
|
518
|
+
# include Hierarchable
|
|
518
519
|
# hierarched parent_source: :parent,
|
|
519
520
|
# additional_descendant_associations: [:some_association]
|
|
520
521
|
# end
|
|
@@ -523,7 +524,7 @@ module Hierarchable
|
|
|
523
524
|
# that should be used. In that case, we can specify it like this:
|
|
524
525
|
#
|
|
525
526
|
# class A
|
|
526
|
-
# include
|
|
527
|
+
# include Hierarchable
|
|
527
528
|
# hierarched parent_source: :parent,
|
|
528
529
|
# descendant_associations: [:some_association]
|
|
529
530
|
# end
|
|
@@ -682,11 +683,15 @@ module Hierarchable
|
|
|
682
683
|
def hierarchy_parent_changed?
|
|
683
684
|
# FIXME: We need to figure out how to deal with updating the
|
|
684
685
|
# object_hierarchy_ancestry_path, object_hierarchy_full_path, etc.,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
686
|
+
return true unless persisted?
|
|
687
|
+
|
|
688
|
+
source = hierarchy_parent_source
|
|
689
|
+
return false if source.blank?
|
|
690
|
+
|
|
691
|
+
changed_method = "#{source}_id_changed?"
|
|
692
|
+
public_send(changed_method) if respond_to?(changed_method)
|
|
693
|
+
|
|
694
|
+
send(source).id == hierarchy_parent_id
|
|
690
695
|
end
|
|
691
696
|
|
|
692
697
|
# Update the hierarchy_ancestors_path if the hierarchy has changed.
|
|
@@ -699,7 +704,6 @@ module Hierarchable
|
|
|
699
704
|
def class_for_association(association)
|
|
700
705
|
self.association(association)
|
|
701
706
|
.reflection
|
|
702
|
-
.
|
|
703
|
-
.safe_constantize
|
|
707
|
+
.klass
|
|
704
708
|
end
|
|
705
709
|
end
|
data/lib/hierarchable/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hierarchable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrick R. Schmid
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-01-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|