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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac67b8aa97065b5917fe0a13e8016d14047cac537bcbb74f8d2910614d86d0da
4
- data.tar.gz: effb465602763db73be3f247daf54fe523eb3fad1ac489fe75df26f08fd4df0b
3
+ metadata.gz: 77318268a18001072d590f7ad65524e5f608923cea6c6e757946ad164862518b
4
+ data.tar.gz: 7740d0be435b42dd701fc626eaa706b58c50688c0bb7639da9caf8b5864d3f3b
5
5
  SHA512:
6
- metadata.gz: f873a3c653dd0eff928657715c49e71eead1080a9798ef7fb97b6d9df296fa4eb686f1335b2e2ba8d1f44af16065246a2918dd864e2b60b29542dcb0772361cc
7
- data.tar.gz: 0be6318e611e86efec91acb95fb4225c653d43b519dece0444c15eeddd3b58b3aff9815dfaebd013f1aec9d1da64befac6fc23fe30fdc00a85b37abd3fc9ddb2
6
+ metadata.gz: '078378d734ddc00ccfcecf685fdd142e581560af7444a34985172c354eae1aeedb91ea98a2b08fd47a20728ce8d594c5d965a49409e7957236549b34352a852f'
7
+ data.tar.gz: 4b9192aec201abb47df5be7589a207c46131fb3544bb2b7cb439dd5c4d6a5df4fe09bc98e32aba14b72b2f3aa789295933226793cb282741a90f1dcd442f38ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hierarchable (0.3.0)
4
+ hierarchable (0.3.1)
5
5
  activerecord (> 4.2.0)
6
6
  activesupport (> 4.2.0)
7
7
 
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 Hierarched
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 Hierarched
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 Hierarched
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 Hierarched
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
- if hierarchy_parent_source.present?
686
- public_send("#{hierarchy_parent_source}_id_changed?")
687
- else
688
- false
689
- end
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
- .class_name
703
- .safe_constantize
707
+ .klass
704
708
  end
705
709
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hierarchable
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
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.0
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: 2022-12-24 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler