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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d92b8d417bb5cd8a6d5ad86ffef5578d49d402e2b5ea8659d0ceaa45f6673332
4
- data.tar.gz: 2f59330b23a407dafdae7841e0b6fea0f48bc5ef23eda037c9d5daac3019a57d
3
+ metadata.gz: 1818a52d06b6fe933cb0ef212d2fa5a3f5fbcfc5bc1c425a277e937099f2fbc7
4
+ data.tar.gz: 0e8700c3b160be17c40e29c9a95e0f560367e312abad8328b7f0b72c7e691099
5
5
  SHA512:
6
- metadata.gz: c94cd745e5647381531ade5e39c89ebae55a580204718f26dc09ee81776f0e173d57d60ad4a407f4ee72f38560ba76250de0cf89bed139c522ca1afbfe8a0aeb
7
- data.tar.gz: 6f375e32110ceddf81c3fff4a6cb5c398392da8380d61457de0a8cb1fd0dae92009bbe939cefbaf1f65fd646b3b62ae1cc2fc39311e4650d1094bc4061b3cc6d
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) [![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)
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
- # * +class_or_item+ - Class name or top level times
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(class_or_item, mover = nil)
25
- if class_or_item.is_a? Array
26
- items = class_or_item.reject { |e| !e.root? }
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
- class_or_item = class_or_item.roots if class_or_item.respond_to?(:scope)
29
- items = Array(class_or_item)
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
- move_to node, :child
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
- if node.children.empty?
48
+ siblings = node == :root ? roots : node.children
49
+ if siblings.empty?
45
50
  move_to_child_of(node)
46
- elsif node.children.count == index
47
- move_to_right_of(node.children.last)
51
+ elsif siblings.count == index
52
+ move_to_right_of(siblings.last)
48
53
  else
49
- my_position = node.children.to_a.index(self)
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(node.children[index])
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(node.children[index])
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
- descendants.each do |model|
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
- errors.add(:base, :"restrict_dependent_destroy.#{Rails::VERSION::MAJOR < 5 ? 'many' : 'has_many'}", record: record)
51
- return false
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
@@ -93,6 +93,10 @@ module CollectiveIdea
93
93
  end
94
94
  end
95
95
 
96
+ def roots
97
+ nested_set_scope.where(parent_id: nil)
98
+ end
99
+
96
100
  protected
97
101
 
98
102
  def compute_level
@@ -129,7 +129,9 @@ module CollectiveIdea #:nodoc:
129
129
 
130
130
  def prevent_impossible_move
131
131
  if !root && !instance.move_possible?(target)
132
- raise ImpossibleMove, "Impossible move, target node cannot be inside moved tree."
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeNestedSet
4
- VERSION = '3.5.0' unless defined?(::AwesomeNestedSet::VERSION)
4
+ VERSION = '3.7.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.5.0
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
- MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
16
- L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjEwNjIzMDkyNzU2WhcNMjIwNjIzMDky
17
- NzU2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
18
- CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQD0CYnD37uLlJ3Urla2EnnUQ8S6s16k
19
- AGMpAzpmARo8YwSqtYMJVGyBzUeI7y93Fk9ncswhIFSH/hnh/Ouat/ki9flHlZ+w
20
- anv0M+9v3wCLyZSC5BQIWpoduFM/fuvLoDUJDWxL50RjwMS0qo2x2LvfQdHN8gn3
21
- JdSIV5WLJKIvlmIl9S3pw0JO5KRUGn1PcBO7C0S0SlbhVjRHtlao1ycWUULsX109
22
- hCh39MPGtnZpdCcxheh0TH/UA/jV0/du9/rQdoidkNHkaC24pPfBJ3nS+rAbWaHP
23
- WmP+0rjfk/XnGBu/HZpKvlnwQjP3QdK4UMtWl8zewqFMNcIiBRALQugnL/SfrP/4
24
- CSlha9LwkiE6ByeY4WGnNjNqpi5J3IzjEkZRAxG7u9gCB3FzTaBTyXZYI6jplYNw
25
- TcCJIBHuoPaa+m9brpjb3Uv94nfM97ZP+OmpGYCCAMq4TT7OOV+t8wJc0w8bb0FO
26
- ROhmVNTxrBaNcl6MkZn88EMRCsGgoWklOG0CAwEAAaNxMG8wCQYDVR0TBAIwADAL
27
- BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu7pbme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mmaZjaPrNkJ4wNaeJPZPPgDmL1XKJavQ8xZ/nwGF
37
+ VXf+6/IyX9OrQwL2uw0b+1NiR2gFpOLcOy2ixKdua13S9CWRRsR3VJve+PIyycC7
38
+ aLV+FI9i9b1YUXG2gDKqLOkF/FNBWNckAmGj7kYkdLG76G5aRGP0HvfKbIiQ3HTC
39
+ jAtsfxiSgc0fAw==
38
40
  -----END CERTIFICATE-----
39
- date: 2022-02-08 00:00:00.000000000 Z
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: '7.1'
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: '7.1'
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: '12'
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: '12'
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.2.32
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