hierarchable 0.2.0 → 0.2.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: 2cbb9e575443a02be4dff5614306785def4eecb5a7738af39261a9001de4739c
4
- data.tar.gz: fb740c37795bafefbb095ce5e0bf1a0cf42b80771976f79dda4919b87bd4b3da
3
+ metadata.gz: f108839bd5cf2491856dfdcc1af95e0d50204f32e467c22bb3f4925d0028f5be
4
+ data.tar.gz: 2379a67ad164232c8efb8c33f8ca6117c6e51387feb39585b4e114ce16542736
5
5
  SHA512:
6
- metadata.gz: b63216b7d4c1887f8787f3775ab4f4781be9103723db3c132a1c5b87ed504ebe97129cec288662aff04e9d7755a5f567e6eb3a54b8a4a29d88fd5fb9f521582f
7
- data.tar.gz: 71dee24abbeced1a0b5f13d0f8f8b0aa8bc6863f77a3f3c47e6286d7dfd77a1a4fbf8e8bb68c8dab95e9d17be3d28ddbcaa6d9ee55d34d658f6fba9db0ef97c5
6
+ metadata.gz: 88822385da9430f6183eafbc4873a7b3009461d733768453212c3abaf615bca2e318da1c36ac3fb9a4d46bdb072fcd07655069a9148a314212915e205f34baa0
7
+ data.tar.gz: bc9b0a309a1e31d7da843ff2ed5f1e75384f9812f63bde5d759018f72de51ebab45e8ea32d45f79cd7f12451d56b439bb69b32b2af0cbc06ee62eeab17ca7d44
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hierarchable (0.2.0)
4
+ hierarchable (0.2.1)
5
5
  activerecord (> 4.2.0)
6
6
  activesupport (> 4.2.0)
7
7
 
data/README.md CHANGED
@@ -183,15 +183,25 @@ project.hierarchy_descendants(models: :this)
183
183
  task.hierarchy_siblings
184
184
  ```
185
185
 
186
- In order to figure out the potential descendants of an object we need to inspect the object and query all relations to to see if any of those have this object as an ancestor. In most cases these relations can be inferred correctly by getting all of the `has_many` relationships that a model has defined. However there are times when we need to manually add a child relation to be inspected. This can be done in one of two ways.
186
+ In order to figure out the potential descendants of an object we need to inspect the object and query all relations to to see if any of those have this object as an ancestor. In many cases these relations can be inferred correctly by getting all of the `has_many` relationships that a model has defined. To be safe and not return potential duplicate associations, the only associations that are automatically detected are the ones that are the pluralized form of the model name.
187
187
 
188
- The most common case is if we want to specify additional associations. This will take all of the associations that can be auto-detected and also add in the one provided.
188
+ ```ruby
189
+ class Project
190
+ has_many :tasks
191
+ has_many :completed_tasks, -> { completed }, class_name: 'Task'
192
+ has_many :timestamps, class_name: 'MetricLibrary::Timestamp`
193
+ end
194
+ ```
195
+
196
+ In the `Project` model defined above, only the `:tasks` association will be used for finding descendants.
197
+
198
+ However there are times when we need to manually add a child relation to be inspected. This can be done in one of two ways. The most common case is if we want to specify additional associations. This will take all of the associations that can be auto-detected and also add in the one provided.
189
199
 
190
200
  ```ruby
191
201
  class SomeObject
192
202
  include Hierarched
193
203
  hierarched parent_source: :parent,
194
- additional_descendant_associations: [:some_association]
204
+ additional_descendant_associations: [:some_association]
195
205
  end
196
206
  ```
197
207
 
@@ -201,7 +211,7 @@ There may also be a case when we want exact control over what associations that
201
211
  class SomeObject
202
212
  include Hierarched
203
213
  hierarched parent_source: :parent,
204
- descendant_associations: [:some_association]
214
+ descendant_associations: [:some_association]
205
215
  end
206
216
  ```
207
217
 
@@ -77,7 +77,7 @@ module Hierarchable
77
77
  self.hierarchable_config = {
78
78
  parent_source: opts.fetch(:parent_source, nil),
79
79
  additional_descendant_associations: opts.fetch(
80
- :descendant_associations, []
80
+ :additional_descendant_associations, []
81
81
  ),
82
82
  descendant_associations: opts.fetch(:descendant_associations, nil),
83
83
  path_separator: opts.fetch(
@@ -382,10 +382,10 @@ module Hierarchable
382
382
  hierarchy_root_id: id
383
383
  )
384
384
  else
385
- path = public_send(:hierarchy_ancestors_path)
385
+ path = public_send(:hierarchy_full_path)
386
386
  model.where(
387
387
  'hierarchy_ancestors_path LIKE ?',
388
- "#{model.sanitize_sql_like(path)}_%"
388
+ "#{model.sanitize_sql_like(path)}%"
389
389
  )
390
390
  end
391
391
  if model == self.class
@@ -421,10 +421,14 @@ module Hierarchable
421
421
  # Return all of the `has_many` association names this class class has as a
422
422
  # list of symbols.
423
423
  #
424
- # The assumption is that all of the associations we care about for
425
- # getting descendants can easily be obtained directly from inspecting
426
- # the class. If there are some associations that need to be manually
427
- # added, one simply specify them when setting up the model.
424
+ # In order to be safe and not return potential duplicate associations,
425
+ # the only associations that are automatically
426
+ # detected are the ones that are the pluralized form of the model name.
427
+ # For example, if a model as the association `has_many :tasks`, there
428
+ # will need to be a Task model for this association to be kept.
429
+ #
430
+ # If there are some associations that need to be manually
431
+ # added, one simply needs to specify them when setting up the model.
428
432
  #
429
433
  # The most common case is if we want to specify additional associations.
430
434
  # This will take all of the associations that can be auto-detected and
@@ -458,7 +462,7 @@ module Hierarchable
458
462
  .reject(&:through_reflection?)
459
463
  .map(&:name)
460
464
  associations += hierarchable_config[:additional_descendant_associations]
461
- associations
465
+ associations.uniq
462
466
  end
463
467
 
464
468
  # Return the string representation of the current object in the format when
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hierarchable
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.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.2.0
4
+ version: 0.2.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-22 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler