awesome_nested_set 3.2.0 → 3.4.0
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG +24 -0
- data/README.md +3 -1
- data/lib/awesome_nested_set/awesome_nested_set.rb +5 -5
- data/lib/awesome_nested_set/model.rb +24 -17
- data/lib/awesome_nested_set/move.rb +17 -3
- data/lib/awesome_nested_set/version.rb +1 -1
- metadata +35 -9
- metadata.gz.sig +4 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5145938ca7a83f2c7f17b21792d96b43fc7c3e7ad90827af1e54bfc69b67d455
|
4
|
+
data.tar.gz: a7c20bb47b946a37e4946ca73577f292679e85624aeb03f75762be7b1e3bc3d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5af92810fd9120cbc84f7ea9f70b444a9331c4ac532e80b03a7c88a506f63a72e80d84ee0b536dfa8f2691c3351d922d55812149188670d45c3945c91a8a651
|
7
|
+
data.tar.gz: 9abe2f9c68010fe4f8105949afc7ecb9941d0897d89bdc0e994920f7a4dec41b2ee1e372e52bc947cbce8395eedec18546d34ce873ba2e9694a53e4b6ab7ea95
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
Unreleased version
|
2
|
+
|
3
|
+
* [Compare to 3.4.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.4.0...master)
|
4
|
+
|
5
|
+
3.4.0
|
6
|
+
* Keep current scope when calling `roots` [Petrik de Heus](https://github.com/p8)
|
7
|
+
* STI record now can update counter cache correctly [Issei Murasawa](http://github.com/issei-m)
|
8
|
+
* [Compare to 3.3.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.3.1...master)
|
9
|
+
|
10
|
+
3.3.1
|
11
|
+
* Add belongs_to :polymorphic key option only when used [Filippo Liverani](https://github.com/filippoliverani)
|
12
|
+
* [Compare to 3.3.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.3.0...v3.3.1)
|
13
|
+
|
14
|
+
3.3.0
|
15
|
+
* Update for compatibility with Rails 6.1 which no longer inherits scoping
|
16
|
+
(Messages of the form "DEPRECATION WARNING: Class level methods will no longer inherit scoping from ...") [Marc Rohloff](https://github.com/marcrohloff)
|
17
|
+
* Fix ruby 2.7 keyword parameters deprecation warning [Krisdigital](https://github.com/krisdigital)
|
18
|
+
* [Compare to 3.2.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.2.1...v3.3.0)
|
19
|
+
|
20
|
+
3.2.1
|
21
|
+
* Don't reload in after_save callback. [Petrik de Heus](https://github.com/p8)
|
22
|
+
* Fix deprecation warning "Passing a range to `#in` is deprecated". [Konstantin Mochalov](https://github.com/kolen)
|
23
|
+
* [Compare to 3.2.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.2.0...v3.2.1)
|
24
|
+
|
1
25
|
3.2.0
|
2
26
|
* Add support for Rails 6.0 [Stefan Andersen](https://github.com/stfnndrsn) and [Damian Legawiec](https://github.com/damianlegawiec) and [Jonathan Tapia](https://github.com/jtapia) and [Alex](https://github.com/a-ta-ta)
|
3
27
|
* [Compare to 3.1.4](https://github.com/collectiveidea/awesome_nested_set/compare/v3.1.4...v3.2.0)
|
data/README.md
CHANGED
@@ -6,7 +6,8 @@
|
|
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.1 supports Rails 5 & 4. Version 2 supports Rails 3.
|
9
|
+
Version 3.2 supports Rails 6, 3.1 supports Rails 5 & 4. Version 2 supports Rails 3.
|
10
|
+
Gem versions prior to 2.0 support Rails 2.
|
10
11
|
|
11
12
|
## What makes this so awesome?
|
12
13
|
|
@@ -65,6 +66,7 @@ Run `rake rdoc` to generate the API docs and see [CollectiveIdea::Acts::NestedSe
|
|
65
66
|
You can pass various options to `acts_as_nested_set` macro. Configuration options are:
|
66
67
|
|
67
68
|
* `parent_column`: specifies the column name to use for keeping the position integer (default: parent_id)
|
69
|
+
* `primary_column`: specifies the column name to use as the inverse of the parent column (default: id)
|
68
70
|
* `left_column`: column name for left boundary data (default: lft)
|
69
71
|
* `right_column`: column name for right boundary data (default: rgt)
|
70
72
|
* `depth_column`: column name for the depth data default (default: depth)
|
@@ -25,8 +25,8 @@ module CollectiveIdea #:nodoc:
|
|
25
25
|
#
|
26
26
|
# * +:parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id)
|
27
27
|
# * +:primary_column+ - specifies the column name to use as the inverse of the parent column (default: id)
|
28
|
-
# * +:left_column+ - column name for left
|
29
|
-
# * +:right_column+ - column name for right
|
28
|
+
# * +:left_column+ - column name for left boundary data, default "lft"
|
29
|
+
# * +:right_column+ - column name for right boundary data, default "rgt"
|
30
30
|
# * +:depth_column+ - column name for the depth data, default "depth"
|
31
31
|
# * +:scope+ - restricts what is to be considered a list. Given a symbol, it'll attach "_id"
|
32
32
|
# (if it hasn't been already) and use that as the foreign key restriction. You
|
@@ -88,7 +88,7 @@ module CollectiveIdea #:nodoc:
|
|
88
88
|
end
|
89
89
|
|
90
90
|
has_many :children, -> { order(order_column_name => :asc) },
|
91
|
-
has_many_children_options
|
91
|
+
**has_many_children_options
|
92
92
|
end
|
93
93
|
|
94
94
|
def acts_as_nested_set_relate_parent!
|
@@ -98,11 +98,11 @@ module CollectiveIdea #:nodoc:
|
|
98
98
|
:primary_key => primary_column_name,
|
99
99
|
:counter_cache => acts_as_nested_set_options[:counter_cache],
|
100
100
|
:inverse_of => (:children unless acts_as_nested_set_options[:polymorphic]),
|
101
|
-
:polymorphic => acts_as_nested_set_options[:polymorphic],
|
102
101
|
:touch => acts_as_nested_set_options[:touch]
|
103
102
|
}
|
103
|
+
options[:polymorphic] = true if acts_as_nested_set_options[:polymorphic]
|
104
104
|
options[:optional] = true if ActiveRecord::VERSION::MAJOR >= 5
|
105
|
-
belongs_to :parent, options
|
105
|
+
belongs_to :parent, **options
|
106
106
|
end
|
107
107
|
|
108
108
|
def acts_as_nested_set_default_options
|
@@ -52,7 +52,7 @@ module CollectiveIdea #:nodoc:
|
|
52
52
|
|
53
53
|
# Iterates over tree elements and determines the current level in the tree.
|
54
54
|
# Only accepts default ordering, odering by an other column than lft
|
55
|
-
# does not work. This method is much more
|
55
|
+
# does not work. This method is much more efficient than calling level
|
56
56
|
# because it doesn't require any additional database queries.
|
57
57
|
#
|
58
58
|
# Example:
|
@@ -79,9 +79,8 @@ module CollectiveIdea #:nodoc:
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def nested_set_scope(options = {})
|
82
|
-
|
83
|
-
|
84
|
-
where(options[:conditions]).order(options.delete(:order))
|
82
|
+
order = scope_order_from_options(options)
|
83
|
+
where(options[:conditions]).order(order)
|
85
84
|
end
|
86
85
|
|
87
86
|
def primary_key_scope(id)
|
@@ -95,6 +94,12 @@ module CollectiveIdea #:nodoc:
|
|
95
94
|
def roots
|
96
95
|
nested_set_scope.children_of nil
|
97
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def scope_order_from_options(options)
|
101
|
+
options.fetch(:order, { order_column_name => :asc })
|
102
|
+
end
|
98
103
|
end # end class methods
|
99
104
|
|
100
105
|
# Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
|
@@ -139,13 +144,9 @@ module CollectiveIdea #:nodoc:
|
|
139
144
|
# performs finds on the base ActiveRecord class, using the :scope
|
140
145
|
# declared in the acts_as_nested_set declaration.
|
141
146
|
def nested_set_scope(options = {})
|
142
|
-
|
143
|
-
options[:conditions] = scopes.inject({}) do |conditions,attr|
|
144
|
-
conditions.merge attr => self[attr]
|
145
|
-
end
|
146
|
-
end
|
147
|
+
add_scope_conditions_to_options(options)
|
147
148
|
|
148
|
-
self.class.base_class.nested_set_scope options
|
149
|
+
self.class.base_class.default_scoped.nested_set_scope options
|
149
150
|
end
|
150
151
|
|
151
152
|
# Separate an other `nested_set_scope` for unscoped model
|
@@ -153,10 +154,10 @@ module CollectiveIdea #:nodoc:
|
|
153
154
|
# Only activerecord callbacks need unscoped model to handle the nested set records
|
154
155
|
# And class level `nested_set_scope` seems just for query `root` `child` .. etc
|
155
156
|
# I think we don't have to provide unscoped `nested_set_scope` in class level.
|
156
|
-
def nested_set_scope_without_default_scope(
|
157
|
-
|
158
|
-
|
159
|
-
|
157
|
+
def nested_set_scope_without_default_scope(options = {})
|
158
|
+
add_scope_conditions_to_options(options)
|
159
|
+
|
160
|
+
self.class.base_class.unscoped.nested_set_scope options
|
160
161
|
end
|
161
162
|
|
162
163
|
def to_text
|
@@ -167,6 +168,13 @@ module CollectiveIdea #:nodoc:
|
|
167
168
|
|
168
169
|
protected
|
169
170
|
|
171
|
+
def add_scope_conditions_to_options(options)
|
172
|
+
scopes = scope_column_names
|
173
|
+
return if scopes.empty?
|
174
|
+
|
175
|
+
options[:conditions] = scopes.map { |attr| [attr, self[attr] ] }.to_h
|
176
|
+
end
|
177
|
+
|
170
178
|
def without_self(scope)
|
171
179
|
return scope if new_record?
|
172
180
|
scope.where(["#{self.class.quoted_table_name}.#{self.class.quoted_primary_column_name} != ?", self.primary_id])
|
@@ -200,7 +208,6 @@ module CollectiveIdea #:nodoc:
|
|
200
208
|
return unless has_depth_column?
|
201
209
|
|
202
210
|
in_tenacious_transaction do
|
203
|
-
reload
|
204
211
|
update_depth(level)
|
205
212
|
end
|
206
213
|
end
|
@@ -237,12 +244,12 @@ module CollectiveIdea #:nodoc:
|
|
237
244
|
|
238
245
|
# Decrease the counter for all old parents
|
239
246
|
if old_parent = self.parent
|
240
|
-
|
247
|
+
old_parent.class.decrement_counter(acts_as_nested_set_options[:counter_cache], old_parent)
|
241
248
|
end
|
242
249
|
|
243
250
|
# Increase the counter for all new parents
|
244
251
|
if new_parent = self.reload.parent
|
245
|
-
|
252
|
+
new_parent.class.increment_counter(acts_as_nested_set_options[:counter_cache], new_parent)
|
246
253
|
end
|
247
254
|
end
|
248
255
|
|
@@ -41,9 +41,21 @@ module CollectiveIdea #:nodoc:
|
|
41
41
|
delegate :base_class, :to => :instance_class, :prefix => :instance
|
42
42
|
|
43
43
|
def where_statement(left_bound, right_bound)
|
44
|
-
instance_arel_table[left_column_name].
|
44
|
+
instance_arel_table[left_column_name].between(left_bound..right_bound).
|
45
|
+
or(instance_arel_table[right_column_name].between(left_bound..right_bound))
|
46
|
+
end
|
47
|
+
|
48
|
+
# Before Arel 6, there was 'in' method, which was replaced
|
49
|
+
# with 'between' in Arel 6 and now gives deprecation warnings
|
50
|
+
# in verbose mode. This is patch to support rails 4.0 (Arel 4)
|
51
|
+
# and 4.1 (Arel 5).
|
52
|
+
module LegacyWhereStatementExt
|
53
|
+
def where_statement(left_bound, right_bound)
|
54
|
+
instance_arel_table[left_column_name].in(left_bound..right_bound).
|
45
55
|
or(instance_arel_table[right_column_name].in(left_bound..right_bound))
|
56
|
+
end
|
46
57
|
end
|
58
|
+
prepend LegacyWhereStatementExt unless Arel::Predications.method_defined?(:between)
|
47
59
|
|
48
60
|
def conditions(a, b, c, d)
|
49
61
|
_conditions = case_condition_for_direction(:quoted_left_column_name) +
|
@@ -84,8 +96,10 @@ module CollectiveIdea #:nodoc:
|
|
84
96
|
|
85
97
|
def lock_nodes_between!(left_bound, right_bound)
|
86
98
|
# select the rows in the model between a and d, and apply a lock
|
87
|
-
instance_base_class.
|
88
|
-
|
99
|
+
instance_base_class.default_scoped.nested_set_scope.
|
100
|
+
right_of(left_bound).left_of_right_side(right_bound).
|
101
|
+
select(primary_column_name).
|
102
|
+
lock(true)
|
89
103
|
end
|
90
104
|
|
91
105
|
def root
|
metadata
CHANGED
@@ -1,16 +1,42 @@
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
8
|
- Daniel Morrison
|
9
9
|
- Philip Arndt
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
|
-
cert_chain:
|
13
|
-
|
12
|
+
cert_chain:
|
13
|
+
- |
|
14
|
+
-----BEGIN CERTIFICATE-----
|
15
|
+
MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
|
16
|
+
L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjAwNTEwMjIxOTQ2WhcNMjEwNTEwMjIx
|
17
|
+
OTQ2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
|
18
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDT+JzHYPGMYJt9ct2DCsbIymn1uJJp
|
19
|
+
HnDkQESfsGe40jTC90oF2iVbVOkaacNc1N3CSWUZvZjuygUuS86P6/kpBILGdO2+
|
20
|
+
bkXXKtfGC2YGGx9TdNLpCb4925vQHvdFeKXGpQDZdDw1SNC6zraZou47CvOE1cl2
|
21
|
+
Bp+1QMZuGRZ4+5CzOEWDWurjqce3O1jUEbyBB7z5H0h/YEaxfXipxhL1Dhi0sgkH
|
22
|
+
qP/e6SxzifdifdZCksJFQ06a1ji9hJY6eM23qbv/aaluVHAZSVBAQBS7rYniLo+N
|
23
|
+
G4vpFhoubQO5u8UluUtCaPUpI/qOvVcSaZn3ZkzlMwC8b1RwAeXBQmtFE2wnrv2i
|
24
|
+
ovTwoN7rHchwhgaHbkuFh4Wr92wGbrWL7J+X8rWKk1f8RF4kvtNE/NA6YrkxTpVh
|
25
|
+
QMyDmekt7rTxvcq2NneLGroWIUVCx/JID+Jw492LKQ6Sl1/P2TRzdEDtqZAZL0gt
|
26
|
+
xlWeMUfGG2D/gLnhs5qnaFaWQwGTmBnTgHcCAwEAAaNxMG8wCQYDVR0TBAIwADAL
|
27
|
+
BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEqtAyQVxPgKsrgoTQ1YmaIu/fmvMBoGA1Ud
|
28
|
+
EQQTMBGBD2dlbXNAcC5hcm5kdC5pbzAaBgNVHRIEEzARgQ9nZW1zQHAuYXJuZHQu
|
29
|
+
aW8wDQYJKoZIhvcNAQELBQADggGBALu2HM50B8xqlAXkCwavJDvWWtV9pG1igFUg
|
30
|
+
friZRWprUQ5nTaNmAd8p8qbJQwaIK2gt+DfYWfB9LtKnQTfbhLRBbmJ7zYw8LjKY
|
31
|
+
PwCs4RWjDAiuyCO3ppfsz+1bsMUXPLgWlaUkXsUy3nr2NruEFTO9zu3wGYQQ93Tt
|
32
|
+
vYSHOnP35UB4QjsjNrOO7FBaQfy6O909PP+GnVcJ62s9c26voJz63RSolwY7Jydw
|
33
|
+
XUlG68jjJKSoDHRzVTmNB7sX8rs8P2kvYkpIUXPHyls3mWBWjBWbdEYWESZrxI2x
|
34
|
+
dS7jY3AnfqhvsWra2pSREb2IDqPnJrHVOejnEI/zuuufUxLwDx3AC6SMdsyWkZ7V
|
35
|
+
9OmLt2rg75Sct6h2220lO5ySqYtqAXuOMBDGv5L0zLalx1g8LACA7uILTKVWh8B8
|
36
|
+
Hsej0MQ3drCB1eA4c9OXdCUQJnY2aLTq3uNvTbZvoTgWK55eq3KLBJ4zzoKZ4tBX
|
37
|
+
/HIFI/fEwYlI1Ji3oikUrHkc4rWgaQ==
|
38
|
+
-----END CERTIFICATE-----
|
39
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
14
40
|
dependencies:
|
15
41
|
- !ruby/object:Gem::Dependency
|
16
42
|
name: activerecord
|
@@ -128,14 +154,14 @@ dependencies:
|
|
128
154
|
requirements:
|
129
155
|
- - "~>"
|
130
156
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
157
|
+
version: 4.0.0
|
132
158
|
type: :development
|
133
159
|
prerelease: false
|
134
160
|
version_requirements: !ruby/object:Gem::Requirement
|
135
161
|
requirements:
|
136
162
|
- - "~>"
|
137
163
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
164
|
+
version: 4.0.0
|
139
165
|
description: An awesome nested set implementation for Active Record
|
140
166
|
email: info@collectiveidea.com
|
141
167
|
executables: []
|
@@ -166,7 +192,7 @@ homepage: http://github.com/collectiveidea/awesome_nested_set
|
|
166
192
|
licenses:
|
167
193
|
- MIT
|
168
194
|
metadata: {}
|
169
|
-
post_install_message:
|
195
|
+
post_install_message:
|
170
196
|
rdoc_options:
|
171
197
|
- "--main"
|
172
198
|
- README.md
|
@@ -185,8 +211,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
211
|
- !ruby/object:Gem::Version
|
186
212
|
version: '0'
|
187
213
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
189
|
-
signing_key:
|
214
|
+
rubygems_version: 3.1.4
|
215
|
+
signing_key:
|
190
216
|
specification_version: 4
|
191
217
|
summary: An awesome nested set implementation for Active Record
|
192
218
|
test_files: []
|
metadata.gz.sig
ADDED