awesome_nested_set 3.6.0 → 3.7.0

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: 2c26151d6850942daadf3035ba6cbb20399efbe348ae4522cf897bb319e6f0de
4
- data.tar.gz: 667d9b0cbd91b90b7b7e8075481ba400c4ecbbd344b204908b2301d2daf690d7
3
+ metadata.gz: 1818a52d06b6fe933cb0ef212d2fa5a3f5fbcfc5bc1c425a277e937099f2fbc7
4
+ data.tar.gz: 0e8700c3b160be17c40e29c9a95e0f560367e312abad8328b7f0b72c7e691099
5
5
  SHA512:
6
- metadata.gz: 38de65793aacc7b68c542b16018a36bcfa9d65af9158d4126bc4ff25c0759531f8b9af605b2bf31894097935be97c15c6eee7ae72616ab56c6388844138558a3
7
- data.tar.gz: 319065889f794e1eec94cb8b1e0113dce515da6430401a20910479e1dd763bce238a31ae36cd957f690564bd42458877367b2dd45c3dbe2c2689c2ae550187df
6
+ metadata.gz: 7927532d26559726db357a3f955f68ed04fb7fe4bda01a074e8379c1df638711554bacabba0b393594734dafbaccc5a97db7bc0122e85e469161ce067a211bff
7
+ data.tar.gz: b6f7a4b82a1a850e48a72ce6852fc4f82e3f8a1a84524d4885ef757020ffaf8239bdafb638796a37f9ab47756de0c7bdc70364764da0eae17072c84ef884260e
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  Unreleased version
2
2
 
3
+ 3.7.0
4
+ * Teach #move_to_child_of and #move_to_child_with_index to accept :root as a parameter [Micah Geisel](https://github.com/botandrose)
5
+ * Add #roots method [Micah Geisel](https://github.com/botandrose)
6
+ * Support Rails 7.2 [Ahmed A. Ibrahim](https://github.com/AhmedAliIbrahim)
7
+
3
8
  3.6.0
4
9
  * Support Rails 7.1 [Harshal Bhakta](https://github.com/harshalbhakta)
5
10
  * Improve ImpossibleMove error message [AlejandroFernandesAntunes](https://github.com/AlejandroFernandesAntunes)
@@ -11,7 +11,7 @@ module CollectiveIdea #:nodoc:
11
11
  # You can pass a block receiving an item and returning the string displayed in the select.
12
12
  #
13
13
  # == Params
14
- # * +class_or_item+ - Class name or top level times
14
+ # * +class_or_items+ - Class name or top level items
15
15
  # * +mover+ - The item that is being move, used to exclude impossible moves
16
16
  # * +&block+ - a block that will be used to display: { |item| ... item.name }
17
17
  #
@@ -21,12 +21,12 @@ module CollectiveIdea #:nodoc:
21
21
  # "#{'–' * i.level} #{i.name}"
22
22
  # }) %>
23
23
  #
24
- def nested_set_options(class_or_item, mover = nil)
25
- if class_or_item.is_a? Array
26
- items = class_or_item.reject { |e| !e.root? }
24
+ def nested_set_options(class_or_items, mover = nil)
25
+ if class_or_items.is_a? Array
26
+ items = class_or_items.reject { |e| !e.root? }
27
27
  else
28
- class_or_item = class_or_item.roots if class_or_item.respond_to?(:scope)
29
- items = Array(class_or_item)
28
+ class_or_items = class_or_items.roots if class_or_items.respond_to?(:scope)
29
+ items = Array(class_or_items)
30
30
  end
31
31
  result = []
32
32
  items.each do |root|
@@ -36,26 +36,31 @@ module CollectiveIdea #:nodoc:
36
36
 
37
37
  # Move the node to the child of another node
38
38
  def move_to_child_of(node)
39
- move_to node, :child
39
+ if node == :root
40
+ move_to_root
41
+ else
42
+ move_to node, :child
43
+ end
40
44
  end
41
45
 
42
46
  # Move the node to the child of another node with specify index
43
47
  def move_to_child_with_index(node, index)
44
- if node.children.empty?
48
+ siblings = node == :root ? roots : node.children
49
+ if siblings.empty?
45
50
  move_to_child_of(node)
46
- elsif node.children.count == index
47
- move_to_right_of(node.children.last)
51
+ elsif siblings.count == index
52
+ move_to_right_of(siblings.last)
48
53
  else
49
- my_position = node.children.to_a.index(self)
54
+ my_position = siblings.index(self)
50
55
  if my_position && my_position < index
51
56
  # e.g. if self is at position 0 and we want to move self to position 1 then self
52
57
  # needs to move to the *right* of the node at position 1. That's because the node
53
58
  # that is currently at position 1 will be at position 0 after the move completes.
54
- move_to_right_of(node.children[index])
59
+ move_to_right_of(siblings[index])
55
60
  elsif my_position && my_position == index
56
61
  # do nothing. already there.
57
62
  else
58
- move_to_left_of(node.children[index])
63
+ move_to_left_of(siblings[index])
59
64
  end
60
65
  end
61
66
  end
@@ -35,9 +35,14 @@ module CollectiveIdea #:nodoc:
35
35
  end
36
36
  end
37
37
 
38
+ # Use reverse to delete from deepest child to parent in order to respect any possible foreign keys
39
+ def decendants_to_destroy_in_order
40
+ descendants.reverse
41
+ end
42
+
38
43
  def destroy_or_delete_descendants
39
44
  if acts_as_nested_set_options[:dependent] == :destroy
40
- descendants.each do |model|
45
+ decendants_to_destroy_in_order.each do |model|
41
46
  model.skip_before_destroy = true
42
47
  model.destroy
43
48
  end
@@ -93,6 +93,10 @@ module CollectiveIdea
93
93
  end
94
94
  end
95
95
 
96
+ def roots
97
+ nested_set_scope.where(parent_id: nil)
98
+ end
99
+
96
100
  protected
97
101
 
98
102
  def compute_level
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeNestedSet
4
- VERSION = '3.6.0' unless defined?(::AwesomeNestedSet::VERSION)
4
+ VERSION = '3.7.0' unless defined?(::AwesomeNestedSet::VERSION)
5
5
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -9,8 +9,36 @@ authors:
9
9
  - Philip Arndt
10
10
  autorequire:
11
11
  bindir: bin
12
- cert_chain: []
13
- date: 2023-10-05 00:00:00.000000000 Z
12
+ cert_chain:
13
+ - |
14
+ -----BEGIN CERTIFICATE-----
15
+ MIIEhjCCAu6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBNMQ0wCwYDVQQDDARnZW1z
16
+ MREwDwYKCZImiZPyLGQBGRYBcDEVMBMGCgmSJom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+ f+faBqfxQHDB3VSEFtCnoVFsCUaC1AdRzWztqS40x5GgQRwcM2llTwMYv5C++gC2
33
+ xPchTvi5FgDI++a05isObUvtNZ/wrZYBhy75ofzGAAMfuB/+XzsGbsOxSwZVlCne
34
+ YLkPa26euounYtKRGLz+X9YD4vDHP5VwsrqsvACMwVGHv+MIM3TQ3TvVrQ7QR9Ov
35
+ yUmuDhnAXep8omj9HyiukfqIdTsIMZK8nMcJH4wXC7mjjOBoyRtMwsQIT8OpwSP9
36
+ A7++64WBwTLbbGSCMCdw8X1kmmaZjaPrNkJ4wNaeJPZPPgDmL1XKJavQ8xZ/nwGF
37
+ VXf+6/IyX9OrQwL2uw0b+1NiR2gFpOLcOy2ixKdua13S9CWRRsR3VJve+PIyycC7
38
+ aLV+FI9i9b1YUXG2gDKqLOkF/FNBWNckAmGj7kYkdLG76G5aRGP0HvfKbIiQ3HTC
39
+ jAtsfxiSgc0fAw==
40
+ -----END CERTIFICATE-----
41
+ date: 2024-08-28 00:00:00.000000000 Z
14
42
  dependencies:
15
43
  - !ruby/object:Gem::Dependency
16
44
  name: activerecord
@@ -21,7 +49,7 @@ dependencies:
21
49
  version: 4.0.0
22
50
  - - "<"
23
51
  - !ruby/object:Gem::Version
24
- version: '7.2'
52
+ version: '8.0'
25
53
  type: :runtime
26
54
  prerelease: false
27
55
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +59,7 @@ dependencies:
31
59
  version: 4.0.0
32
60
  - - "<"
33
61
  - !ruby/object:Gem::Version
34
- version: '7.2'
62
+ version: '8.0'
35
63
  - !ruby/object:Gem::Dependency
36
64
  name: appraisal
37
65
  requirement: !ruby/object:Gem::Requirement
@@ -106,16 +134,22 @@ dependencies:
106
134
  name: rspec-rails
107
135
  requirement: !ruby/object:Gem::Requirement
108
136
  requirements:
109
- - - "~>"
137
+ - - ">="
110
138
  - !ruby/object:Gem::Version
111
139
  version: 4.0.0
140
+ - - "<="
141
+ - !ruby/object:Gem::Version
142
+ version: '6.2'
112
143
  type: :development
113
144
  prerelease: false
114
145
  version_requirements: !ruby/object:Gem::Requirement
115
146
  requirements:
116
- - - "~>"
147
+ - - ">="
117
148
  - !ruby/object:Gem::Version
118
149
  version: 4.0.0
150
+ - - "<="
151
+ - !ruby/object:Gem::Version
152
+ version: '6.2'
119
153
  description: An awesome nested set implementation for Active Record
120
154
  email: info@collectiveidea.com
121
155
  executables: []
@@ -165,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
199
  - !ruby/object:Gem::Version
166
200
  version: '0'
167
201
  requirements: []
168
- rubygems_version: 3.4.13
202
+ rubygems_version: 3.5.11
169
203
  signing_key:
170
204
  specification_version: 4
171
205
  summary: An awesome nested set implementation for Active Record
metadata.gz.sig ADDED
Binary file