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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70956fe8d08167ab96e67894222f423188919dcb05a5a607f33d3372b5c909db
4
- data.tar.gz: cd34dc69edd00532c4cf8315263fb5f4b81c65ce02057600b514cf650bc5ff91
3
+ metadata.gz: d92b8d417bb5cd8a6d5ad86ffef5578d49d402e2b5ea8659d0ceaa45f6673332
4
+ data.tar.gz: 2f59330b23a407dafdae7841e0b6fea0f48bc5ef23eda037c9d5daac3019a57d
5
5
  SHA512:
6
- metadata.gz: 60354ed14c223e08bdec1da6ed56c533d3247ffedc846bf11f5c54b6065e0f3ea886db0a19405eac0dfc30721dd417b8ae441e0a1432dea6eb5caa7dd45dab7f
7
- data.tar.gz: 2ec0377f5fa405db532d6b7bb630d6225157d958e3cf868dabfcdec11536886ab83f809aa6443cfefa59c55f689cbe8ca123b78e845bd8cf233531a333f3bf31
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
- * [Compare to 3.2.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.2.1...master)
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
- [![Build Status](https://travis-ci.org/collectiveidea/awesome_nested_set.svg?branch=master)](https://travis-ci.org/collectiveidea/awesome_nested_set) [![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)
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. Gem versions prior to 2.0 support Rails 2.
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 self.up
35
+ def change
35
36
  create_table :categories do |t|
36
37
  t.string :name
37
- t.integer :parent_id, :null => true, :index => true
38
- t.integer :lft, :null => false, :index => true
39
- t.integer :rgt, :null => false, :index => true
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, :null => false, :default => 0
43
- t.integer :children_count, :null => false, :default => 0
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 => :asc) },
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 exlude impossible moves
16
- # * +&block+ - a block that will be used to display: { |item| ... item.name }
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
- options = {:order => { order_column_name => :asc }}.merge(options)
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
- if (scopes = Array(acts_as_nested_set_options[:scope])).any?
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(*args)
157
- self.class.base_class.unscoped do
158
- nested_set_scope(*args)
159
- end
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
- self.class.decrement_counter(acts_as_nested_set_options[:counter_cache], old_parent)
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
- self.class.increment_counter(acts_as_nested_set_options[:counter_cache], new_parent)
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.right_of(left_bound).left_of_right_side(right_bound).
100
- select(primary_column_name).lock(true)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeNestedSet
4
- VERSION = '3.2.1' unless defined?(::AwesomeNestedSet::VERSION)
4
+ VERSION = '3.5.0' unless defined?(::AwesomeNestedSet::VERSION)
5
5
  end
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.2.1
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
- L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjAwNTEwMjIxOTQ2WhcNMjEwNTEwMjIx
17
- OTQ2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
18
- CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDT+JzHYPGMYJt9ct2DCsbIymn1uJJp
19
- HnDkQESfsGe40jTC90oF2iVbVOkaacNc1N3CSWUZvZjuygUuS86P6/kpBILGdO2+
20
- bkXXKtfGC2YGGx9TdNLpCb4925vQHvdFeKXGpQDZdDw1SNC6zraZou47CvOE1cl2
21
- Bp+1QMZuGRZ4+5CzOEWDWurjqce3O1jUEbyBB7z5H0h/YEaxfXipxhL1Dhi0sgkH
22
- qP/e6SxzifdifdZCksJFQ06a1ji9hJY6eM23qbv/aaluVHAZSVBAQBS7rYniLo+N
23
- G4vpFhoubQ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HsIiV9xrc4BwlwlbitcvNIL
34
+ ZykdSlpTJd0Guy92iYjCJMC09tMRUNxiVBwD3jRGSeW9YAPIZGXIcVlm6srIRDjJ
35
+ o8wB6oOvHAkRXnntOo/4bBDH+ehmgvhh/O/mI+au6C0M430fv+ooH0w08LEXLx1k
36
+ e17ZNASZffbQRP09MH2GZ2AOlkildTX6looWRforZEZi+qamognrozd3MI5QHi1W
37
+ UAZUzHLrrFu7gnkFvLVpxOUf4ItOkA==
38
38
  -----END CERTIFICATE-----
39
- date: 2020-06-23 00:00:00.000000000 Z
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.0'
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.0'
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: '10'
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: '10'
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: 3.8.0
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: 3.8.0
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: http://github.com/collectiveidea/awesome_nested_set
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.1.2
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