awesome_nested_set 3.5.0 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG +9 -0
- data/README.md +2 -2
- data/lib/awesome_nested_set/helper.rb +6 -6
- data/lib/awesome_nested_set/model/movable.rb +12 -7
- data/lib/awesome_nested_set/model/prunable.rb +13 -3
- data/lib/awesome_nested_set/model/relatable.rb +4 -0
- data/lib/awesome_nested_set/move.rb +3 -1
- data/lib/awesome_nested_set/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +40 -32
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1818a52d06b6fe933cb0ef212d2fa5a3f5fbcfc5bc1c425a277e937099f2fbc7
|
4
|
+
data.tar.gz: 0e8700c3b160be17c40e29c9a95e0f560367e312abad8328b7f0b72c7e691099
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7927532d26559726db357a3f955f68ed04fb7fe4bda01a074e8379c1df638711554bacabba0b393594734dafbaccc5a97db7bc0122e85e469161ce067a211bff
|
7
|
+
data.tar.gz: b6f7a4b82a1a850e48a72ce6852fc4f82e3f8a1a84524d4885ef757020ffaf8239bdafb638796a37f9ab47756de0c7bdc70364764da0eae17072c84ef884260e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,14 @@
|
|
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
|
+
|
8
|
+
3.6.0
|
9
|
+
* Support Rails 7.1 [Harshal Bhakta](https://github.com/harshalbhakta)
|
10
|
+
* Improve ImpossibleMove error message [AlejandroFernandesAntunes](https://github.com/AlejandroFernandesAntunes)
|
11
|
+
|
3
12
|
3.5.0
|
4
13
|
* Support Rails 7.0.0 [Peter Berkenbosch](https://github.com/peterberkenbosch) and [Andrew Hampton](https://github.com/andrewhampton)
|
5
14
|
* Make `order_column` option more flexible by removing explicit `=> :asc` [Regis Millet](https://github.com/Kulgar)
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Awesome Nested Set
|
2
2
|
|
3
|
-
[![CI](https://github.com/collectiveidea/awesome_nested_set/actions/workflows/ci.yml/badge.svg)](https://github.com/collectiveidea/awesome_nested_set/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/collectiveidea/awesome_nested_set.svg)](https://codeclimate.com/github/collectiveidea/awesome_nested_set)
|
3
|
+
[![CI](https://github.com/collectiveidea/awesome_nested_set/actions/workflows/ci.yml/badge.svg)](https://github.com/collectiveidea/awesome_nested_set/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/collectiveidea/awesome_nested_set.svg)](https://codeclimate.com/github/collectiveidea/awesome_nested_set)
|
4
4
|
|
5
5
|
|
6
6
|
Awesome Nested Set is an implementation of the nested set pattern for ActiveRecord models.
|
7
7
|
It is a replacement for acts_as_nested_set and BetterNestedSet, but more awesome.
|
8
8
|
|
9
|
-
Version 3.2 supports Rails 6, 3.1 supports Rails 5 & 4. Version 2 supports Rails 3.
|
9
|
+
Older versions: Version 3.2 supports Rails 6, 3.1 supports Rails 5 & 4. Version 2 supports Rails 3.
|
10
10
|
Gem versions prior to 2.0 support Rails 2.
|
11
11
|
|
12
12
|
## What makes this so awesome?
|
@@ -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
|
-
# * +
|
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(
|
25
|
-
if
|
26
|
-
items =
|
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
|
-
|
29
|
-
items = Array(
|
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
|
-
|
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
|
-
|
48
|
+
siblings = node == :root ? roots : node.children
|
49
|
+
if siblings.empty?
|
45
50
|
move_to_child_of(node)
|
46
|
-
elsif
|
47
|
-
move_to_right_of(
|
51
|
+
elsif siblings.count == index
|
52
|
+
move_to_right_of(siblings.last)
|
48
53
|
else
|
49
|
-
my_position =
|
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(
|
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(
|
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
|
-
|
45
|
+
decendants_to_destroy_in_order.each do |model|
|
41
46
|
model.skip_before_destroy = true
|
42
47
|
model.destroy
|
43
48
|
end
|
@@ -47,8 +52,13 @@ module CollectiveIdea #:nodoc:
|
|
47
52
|
elsif acts_as_nested_set_options[:dependent] == :restrict_with_error
|
48
53
|
unless leaf?
|
49
54
|
record = self.class.human_attribute_name(:children).downcase
|
50
|
-
|
51
|
-
|
55
|
+
if Rails::VERSION::MAJOR < 5
|
56
|
+
errors.add(:base, :"restrict_dependent_destroy.many", record: record)
|
57
|
+
return false
|
58
|
+
else
|
59
|
+
errors.add(:base, :"restrict_dependent_destroy.has_many", record: record)
|
60
|
+
throw :abort
|
61
|
+
end
|
52
62
|
end
|
53
63
|
return true
|
54
64
|
elsif acts_as_nested_set_options[:dependent] == :nullify
|
@@ -129,7 +129,9 @@ module CollectiveIdea #:nodoc:
|
|
129
129
|
|
130
130
|
def prevent_impossible_move
|
131
131
|
if !root && !instance.move_possible?(target)
|
132
|
-
|
132
|
+
error_msg = "Impossible move, target node (#{target.class.name},ID: #{target.id})
|
133
|
+
cannot be inside moved tree (#{instance.class.name},ID: #{instance.id})."
|
134
|
+
raise ImpossibleMove, error_msg
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
data.tar.gz.sig
CHANGED
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.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -12,31 +12,33 @@ bindir: bin
|
|
12
12
|
cert_chain:
|
13
13
|
- |
|
14
14
|
-----BEGIN CERTIFICATE-----
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
MIIEhjCCAu6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBNMQ0wCwYDVQQDDARnZW1z
|
16
|
+
MREwDwYKCZImiZPyLGQBGRYBcDEVMBMGCgmSJomT8ixkARkWBWFybmR0MRIwEAYK
|
17
|
+
CZImiZPyLGQBGRYCaW8wHhcNMjQwNzI1MDkzMTM3WhcNMjUwNzI1MDkzMTM3WjBN
|
18
|
+
MQ0wCwYDVQQDDARnZW1zMREwDwYKCZImiZPyLGQBGRYBcDEVMBMGCgmSJomT8ixk
|
19
|
+
ARkWBWFybmR0MRIwEAYKCZImiZPyLGQBGRYCaW8wggGiMA0GCSqGSIb3DQEBAQUA
|
20
|
+
A4IBjwAwggGKAoIBgQCb2WAH3bZwQeiyrc8ihYIM3cDDfiJbUYDxwE4+c8PT+WBO
|
21
|
+
WIC4QMdiVLllwliKoCjDeH14dNHGYBJFFu4+jj+jyzYEPaxPn05N4zUZiFe3oXzf
|
22
|
+
ipaNxdCuilrMrRT0hFclKWvGUT5meVmfxEgX65FPHezv5W4za4ajxfMItUqJCooQ
|
23
|
+
lfXB8sO6j/z94ZpHOzj/HT/q6krXSQWSYGLmb3ZKRIeo8uk3cAcAYBO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F/FNBWNckAmGj7kYkdLG76G5aRGP0HvfKbIiQ3HTC
|
39
|
+
jAtsfxiSgc0fAw==
|
38
40
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
41
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
40
42
|
dependencies:
|
41
43
|
- !ruby/object:Gem::Dependency
|
42
44
|
name: activerecord
|
@@ -47,7 +49,7 @@ dependencies:
|
|
47
49
|
version: 4.0.0
|
48
50
|
- - "<"
|
49
51
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
52
|
+
version: '8.0'
|
51
53
|
type: :runtime
|
52
54
|
prerelease: false
|
53
55
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +59,7 @@ dependencies:
|
|
57
59
|
version: 4.0.0
|
58
60
|
- - "<"
|
59
61
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
62
|
+
version: '8.0'
|
61
63
|
- !ruby/object:Gem::Dependency
|
62
64
|
name: appraisal
|
63
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,28 +122,34 @@ dependencies:
|
|
120
122
|
requirements:
|
121
123
|
- - "~>"
|
122
124
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
125
|
+
version: '13'
|
124
126
|
type: :development
|
125
127
|
prerelease: false
|
126
128
|
version_requirements: !ruby/object:Gem::Requirement
|
127
129
|
requirements:
|
128
130
|
- - "~>"
|
129
131
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
132
|
+
version: '13'
|
131
133
|
- !ruby/object:Gem::Dependency
|
132
134
|
name: rspec-rails
|
133
135
|
requirement: !ruby/object:Gem::Requirement
|
134
136
|
requirements:
|
135
|
-
- - "
|
137
|
+
- - ">="
|
136
138
|
- !ruby/object:Gem::Version
|
137
139
|
version: 4.0.0
|
140
|
+
- - "<="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '6.2'
|
138
143
|
type: :development
|
139
144
|
prerelease: false
|
140
145
|
version_requirements: !ruby/object:Gem::Requirement
|
141
146
|
requirements:
|
142
|
-
- - "
|
147
|
+
- - ">="
|
143
148
|
- !ruby/object:Gem::Version
|
144
149
|
version: 4.0.0
|
150
|
+
- - "<="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '6.2'
|
145
153
|
description: An awesome nested set implementation for Active Record
|
146
154
|
email: info@collectiveidea.com
|
147
155
|
executables: []
|
@@ -191,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
199
|
- !ruby/object:Gem::Version
|
192
200
|
version: '0'
|
193
201
|
requirements: []
|
194
|
-
rubygems_version: 3.
|
202
|
+
rubygems_version: 3.5.11
|
195
203
|
signing_key:
|
196
204
|
specification_version: 4
|
197
205
|
summary: An awesome nested set implementation for Active Record
|
metadata.gz.sig
CHANGED
Binary file
|