awesome_nested_set 3.2.1 → 3.3.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 +8 -1
- data/README.md +2 -1
- data/lib/awesome_nested_set/awesome_nested_set.rb +2 -2
- data/lib/awesome_nested_set/model.rb +24 -11
- data/lib/awesome_nested_set/move.rb +4 -2
- data/lib/awesome_nested_set/version.rb +1 -1
- metadata +3 -3
- 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: 987975770adaff76d0b73ccbb82d5bdc008023485d822ac07e84586a550a2ede
|
4
|
+
data.tar.gz: 35dace0d877e6abcd9cacc806447311eea226d916cf753fb17c23d957a73a398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf339d676ccbb8258b642f7017b950d2d1947e9819648b8e5b6254ad6e460c2e129648de11c969833eabaacdc1a481743c2a0441b7b8a8cfe17242bd2546a3fc
|
7
|
+
data.tar.gz: 492ecf9fac7fe59bc51a60a630a595a5f8c533c3799d7d4cc137e75f8c60b088f717a8b146395779f3835f0bcc0174890c1463fbd23385faea04ad6c57f3a0cd
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
Unreleased version
|
2
|
-
|
2
|
+
|
3
|
+
* [Compare to 3.3.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.3.0...master)
|
4
|
+
|
5
|
+
3.3.0
|
6
|
+
* Update for compatibility with Rails 6.1 which no longer inherits scoping
|
7
|
+
(Messages of the form "DEPRECATION WARNING: Class level methods will no longer inherit scoping from ...") [Marc Rohloff](https://github.com/marcrohloff)
|
8
|
+
* Fix ruby 2.7 keyword parameters deprecation warning [Krisdigital](https://github.com/krisdigital)
|
9
|
+
* [Compare to 3.2.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.2.1...v3.3.0)
|
3
10
|
|
4
11
|
3.2.1
|
5
12
|
* Don't reload in after_save callback. [Petrik de Heus](https://github.com/p8)
|
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
|
|
@@ -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!
|
@@ -102,7 +102,7 @@ module CollectiveIdea #:nodoc:
|
|
102
102
|
:touch => acts_as_nested_set_options[:touch]
|
103
103
|
}
|
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
|
@@ -79,9 +79,13 @@ module CollectiveIdea #:nodoc:
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def nested_set_scope(options = {})
|
82
|
-
|
82
|
+
order = scope_order_from_options(options)
|
83
|
+
default_scoped.where(options[:conditions]).order(order)
|
84
|
+
end
|
83
85
|
|
84
|
-
|
86
|
+
def nested_set_scope_without_default_scope(options = {})
|
87
|
+
order = scope_order_from_options(options)
|
88
|
+
unscoped.where(options[:conditions]).order(order)
|
85
89
|
end
|
86
90
|
|
87
91
|
def primary_key_scope(id)
|
@@ -95,6 +99,12 @@ module CollectiveIdea #:nodoc:
|
|
95
99
|
def roots
|
96
100
|
nested_set_scope.children_of nil
|
97
101
|
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def scope_order_from_options(options)
|
106
|
+
options.fetch(:order, { order_column_name => :asc })
|
107
|
+
end
|
98
108
|
end # end class methods
|
99
109
|
|
100
110
|
# 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,11 +149,7 @@ module CollectiveIdea #:nodoc:
|
|
139
149
|
# performs finds on the base ActiveRecord class, using the :scope
|
140
150
|
# declared in the acts_as_nested_set declaration.
|
141
151
|
def nested_set_scope(options = {})
|
142
|
-
|
143
|
-
options[:conditions] = scopes.inject({}) do |conditions,attr|
|
144
|
-
conditions.merge attr => self[attr]
|
145
|
-
end
|
146
|
-
end
|
152
|
+
add_scope_conditions_to_options(options)
|
147
153
|
|
148
154
|
self.class.base_class.nested_set_scope options
|
149
155
|
end
|
@@ -153,10 +159,10 @@ module CollectiveIdea #:nodoc:
|
|
153
159
|
# Only activerecord callbacks need unscoped model to handle the nested set records
|
154
160
|
# And class level `nested_set_scope` seems just for query `root` `child` .. etc
|
155
161
|
# 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
|
-
|
162
|
+
def nested_set_scope_without_default_scope(options = {})
|
163
|
+
add_scope_conditions_to_options(options)
|
164
|
+
|
165
|
+
self.class.base_class.nested_set_scope_without_default_scope options
|
160
166
|
end
|
161
167
|
|
162
168
|
def to_text
|
@@ -167,6 +173,13 @@ module CollectiveIdea #:nodoc:
|
|
167
173
|
|
168
174
|
protected
|
169
175
|
|
176
|
+
def add_scope_conditions_to_options(options)
|
177
|
+
scopes = scope_column_names
|
178
|
+
return if scopes.empty?
|
179
|
+
|
180
|
+
options[:conditions] = scopes.map { |attr| [attr, self[attr] ] }.to_h
|
181
|
+
end
|
182
|
+
|
170
183
|
def without_self(scope)
|
171
184
|
return scope if new_record?
|
172
185
|
scope.where(["#{self.class.quoted_table_name}.#{self.class.quoted_primary_column_name} != ?", self.primary_id])
|
@@ -96,8 +96,10 @@ module CollectiveIdea #:nodoc:
|
|
96
96
|
|
97
97
|
def lock_nodes_between!(left_bound, right_bound)
|
98
98
|
# select the rows in the model between a and d, and apply a lock
|
99
|
-
instance_base_class.
|
100
|
-
|
99
|
+
instance_base_class.nested_set_scope.
|
100
|
+
right_of(left_bound).left_of_right_side(right_bound).
|
101
|
+
select(primary_column_name).
|
102
|
+
lock(true)
|
101
103
|
end
|
102
104
|
|
103
105
|
def root
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
Hsej0MQ3drCB1eA4c9OXdCUQJnY2aLTq3uNvTbZvoTgWK55eq3KLBJ4zzoKZ4tBX
|
37
37
|
/HIFI/fEwYlI1Ji3oikUrHkc4rWgaQ==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2021-01-03 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
214
|
+
rubygems_version: 3.2.3
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: An awesome nested set implementation for Active Record
|
metadata.gz.sig
CHANGED
Binary file
|