awesome_nested_set 3.2.1 → 3.5.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 +21 -1
- data/README.md +10 -12
- data/lib/awesome_nested_set/awesome_nested_set.rb +4 -4
- data/lib/awesome_nested_set/helper.rb +2 -2
- data/lib/awesome_nested_set/model.rb +23 -15
- data/lib/awesome_nested_set/move.rb +4 -2
- data/lib/awesome_nested_set/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +31 -51
- 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: d92b8d417bb5cd8a6d5ad86ffef5578d49d402e2b5ea8659d0ceaa45f6673332
|
4
|
+
data.tar.gz: 2f59330b23a407dafdae7841e0b6fea0f48bc5ef23eda037c9d5daac3019a57d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c94cd745e5647381531ade5e39c89ebae55a580204718f26dc09ee81776f0e173d57d60ad4a407f4ee72f38560ba76250de0cf89bed139c522ca1afbfe8a0aeb
|
7
|
+
data.tar.gz: 6f375e32110ceddf81c3fff4a6cb5c398392da8380d61457de0a8cb1fd0dae92009bbe939cefbaf1f65fd646b3b62ae1cc2fc39311e4650d1094bc4061b3cc6d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
Unreleased version
|
2
|
-
|
2
|
+
|
3
|
+
3.5.0
|
4
|
+
* Support Rails 7.0.0 [Peter Berkenbosch](https://github.com/peterberkenbosch) and [Andrew Hampton](https://github.com/andrewhampton)
|
5
|
+
* Make `order_column` option more flexible by removing explicit `=> :asc` [Regis Millet](https://github.com/Kulgar)
|
6
|
+
* Updated README to use latest migration syntax [Justin MacCarthy](https://github.com/macarthy)
|
7
|
+
* [Compare to 3.4.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.4.0...v3.5.0)
|
8
|
+
|
9
|
+
3.4.0
|
10
|
+
* Keep current scope when calling `roots` [Petrik de Heus](https://github.com/p8)
|
11
|
+
* STI record now can update counter cache correctly [Issei Murasawa](http://github.com/issei-m)
|
12
|
+
* [Compare to 3.3.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.3.1...v3.4.0)
|
13
|
+
|
14
|
+
3.3.1
|
15
|
+
* Add belongs_to :polymorphic key option only when used [Filippo Liverani](https://github.com/filippoliverani)
|
16
|
+
* [Compare to 3.3.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.3.0...v3.3.1)
|
17
|
+
|
18
|
+
3.3.0
|
19
|
+
* Update for compatibility with Rails 6.1 which no longer inherits scoping
|
20
|
+
(Messages of the form "DEPRECATION WARNING: Class level methods will no longer inherit scoping from ...") [Marc Rohloff](https://github.com/marcrohloff)
|
21
|
+
* Fix ruby 2.7 keyword parameters deprecation warning [Krisdigital](https://github.com/krisdigital)
|
22
|
+
* [Compare to 3.2.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.2.1...v3.3.0)
|
3
23
|
|
4
24
|
3.2.1
|
5
25
|
* Don't reload in after_save callback. [Petrik de Heus](https://github.com/p8)
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Awesome Nested Set
|
2
2
|
|
3
|
-
[![
|
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) [![Security](https://hakiri.io/github/collectiveidea/awesome_nested_set/master.svg)](https://hakiri.io/github/collectiveidea/awesome_nested_set/master)
|
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.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
|
|
@@ -31,22 +32,19 @@ function properly.
|
|
31
32
|
|
32
33
|
```ruby
|
33
34
|
class CreateCategories < ActiveRecord::Migration
|
34
|
-
def
|
35
|
+
def change
|
35
36
|
create_table :categories do |t|
|
36
37
|
t.string :name
|
37
|
-
t.integer :parent_id, :
|
38
|
-
t.integer :lft, :
|
39
|
-
t.integer :rgt, :
|
38
|
+
t.integer :parent_id, null: true, index: true
|
39
|
+
t.integer :lft, null: false, index: true
|
40
|
+
t.integer :rgt, null: false, index: true
|
40
41
|
|
41
42
|
# optional fields
|
42
|
-
t.integer :depth, :
|
43
|
-
t.integer :children_count, :
|
43
|
+
t.integer :depth, null: false, default: 0
|
44
|
+
t.integer :children_count, null: false, default: 0
|
45
|
+
t.timestamps
|
44
46
|
end
|
45
47
|
end
|
46
|
-
|
47
|
-
def self.down
|
48
|
-
drop_table :categories
|
49
|
-
end
|
50
48
|
end
|
51
49
|
```
|
52
50
|
|
@@ -87,8 +87,8 @@ module CollectiveIdea #:nodoc:
|
|
87
87
|
) if acts_as_nested_set_options[ar_callback]
|
88
88
|
end
|
89
89
|
|
90
|
-
has_many :children, -> { order(order_column_name
|
91
|
-
has_many_children_options
|
90
|
+
has_many :children, -> { order(order_column_name) },
|
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
|
@@ -12,8 +12,8 @@ module CollectiveIdea #:nodoc:
|
|
12
12
|
#
|
13
13
|
# == Params
|
14
14
|
# * +class_or_item+ - Class name or top level times
|
15
|
-
# * +mover+ - The item that is being move, used to
|
16
|
-
# * +&block+ - a block that will be used to display: {
|
15
|
+
# * +mover+ - The item that is being move, used to exclude impossible moves
|
16
|
+
# * +&block+ - a block that will be used to display: { |item| ... item.name }
|
17
17
|
#
|
18
18
|
# == Usage
|
19
19
|
#
|
@@ -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)
|
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])
|
@@ -236,12 +244,12 @@ module CollectiveIdea #:nodoc:
|
|
236
244
|
|
237
245
|
# Decrease the counter for all old parents
|
238
246
|
if old_parent = self.parent
|
239
|
-
|
247
|
+
old_parent.class.decrement_counter(acts_as_nested_set_options[:counter_cache], old_parent)
|
240
248
|
end
|
241
249
|
|
242
250
|
# Increase the counter for all new parents
|
243
251
|
if new_parent = self.reload.parent
|
244
|
-
|
252
|
+
new_parent.class.increment_counter(acts_as_nested_set_options[:counter_cache], new_parent)
|
245
253
|
end
|
246
254
|
end
|
247
255
|
|
@@ -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.default_scoped.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
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -13,30 +13,30 @@ cert_chain:
|
|
13
13
|
- |
|
14
14
|
-----BEGIN CERTIFICATE-----
|
15
15
|
MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjEwNjIzMDkyNzU2WhcNMjIwNjIzMDky
|
17
|
+
NzU2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
|
18
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQD0CYnD37uLlJ3Urla2EnnUQ8S6s16k
|
19
|
+
AGMp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L9zwEKPFp1Y5X+z
|
33
|
+
t2jBjYt2ymr1eMWxux6e+N2uKZL4MblHawxvKlI8UHsIiV9xrc4BwlwlbitcvNIL
|
34
|
+
ZykdSlpTJd0Guy92iYjCJMC09tMRUNxiVBwD3jRGSeW9YAPIZGXIcVlm6srIRDjJ
|
35
|
+
o8wB6oOvHAkRXnntOo/4bBDH+ehmgvhh/O/mI+au6C0M430fv+ooH0w08LEXLx1k
|
36
|
+
e17ZNASZffbQRP09MH2GZ2AOlkildTX6looWRforZEZi+qamognrozd3MI5QHi1W
|
37
|
+
UAZUzHLrrFu7gnkFvLVpxOUf4ItOkA==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: 4.0.0
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '7.
|
50
|
+
version: '7.1'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: 4.0.0
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '7.
|
60
|
+
version: '7.1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: appraisal
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,26 +72,6 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: combustion
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: 0.5.2
|
82
|
-
- - "<"
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 0.5.5
|
85
|
-
type: :development
|
86
|
-
prerelease: false
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: 0.5.2
|
92
|
-
- - "<"
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 0.5.5
|
95
75
|
- !ruby/object:Gem::Dependency
|
96
76
|
name: database_cleaner
|
97
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,28 +120,28 @@ dependencies:
|
|
140
120
|
requirements:
|
141
121
|
- - "~>"
|
142
122
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
123
|
+
version: '12'
|
144
124
|
type: :development
|
145
125
|
prerelease: false
|
146
126
|
version_requirements: !ruby/object:Gem::Requirement
|
147
127
|
requirements:
|
148
128
|
- - "~>"
|
149
129
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
130
|
+
version: '12'
|
151
131
|
- !ruby/object:Gem::Dependency
|
152
132
|
name: rspec-rails
|
153
133
|
requirement: !ruby/object:Gem::Requirement
|
154
134
|
requirements:
|
155
135
|
- - "~>"
|
156
136
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
137
|
+
version: 4.0.0
|
158
138
|
type: :development
|
159
139
|
prerelease: false
|
160
140
|
version_requirements: !ruby/object:Gem::Requirement
|
161
141
|
requirements:
|
162
142
|
- - "~>"
|
163
143
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
144
|
+
version: 4.0.0
|
165
145
|
description: An awesome nested set implementation for Active Record
|
166
146
|
email: info@collectiveidea.com
|
167
147
|
executables: []
|
@@ -188,7 +168,7 @@ files:
|
|
188
168
|
- lib/awesome_nested_set/set_validator.rb
|
189
169
|
- lib/awesome_nested_set/tree.rb
|
190
170
|
- lib/awesome_nested_set/version.rb
|
191
|
-
homepage:
|
171
|
+
homepage: https://github.com/collectiveidea/awesome_nested_set
|
192
172
|
licenses:
|
193
173
|
- MIT
|
194
174
|
metadata: {}
|
@@ -211,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
191
|
- !ruby/object:Gem::Version
|
212
192
|
version: '0'
|
213
193
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
194
|
+
rubygems_version: 3.2.32
|
215
195
|
signing_key:
|
216
196
|
specification_version: 4
|
217
197
|
summary: An awesome nested set implementation for Active Record
|
metadata.gz.sig
CHANGED
Binary file
|