awesome_nested_set 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/README.md +20 -11
- data/lib/awesome_nested_set/awesome_nested_set.rb +1 -1
- data/lib/awesome_nested_set/columns.rb +10 -6
- data/lib/awesome_nested_set/model/prunable.rb +3 -1
- data/lib/awesome_nested_set/model/transactable.rb +9 -2
- data/lib/awesome_nested_set/move.rb +4 -1
- data/lib/awesome_nested_set/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5ab643ea1dfe98a3df89d5bf2c142fd22d8d96f
|
4
|
+
data.tar.gz: 3f6089e375d849c9cb600eb4c776c40323b3e67e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3afe6283157bd9937196de7ffe4239dac7be930417b505b306c92685cfdd703d9cf7463317994bc822490f4a426c0c88f3f3425501036cd00b00025a6f81dc8c
|
7
|
+
data.tar.gz: d96cf10ce68aa34ccee951f3b04beec6eebd960748c42502ba48016b3f559cf798c657b2b9b36d4238c38d1ba0dbca08f53dab5f39f3d3bb37044dcb4dafe902
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
3.0.4
|
2
|
+
* Reuse the current model's connection when available [Tim Bugai] [#322](https://github.com/collectiveidea/awesome_nested_set/pull/322)
|
3
|
+
|
4
|
+
3.0.3
|
5
|
+
* Add :nullify option to :dependent functionality to orphan children rather
|
6
|
+
than destroy them.
|
7
|
+
|
1
8
|
3.0.2
|
2
9
|
* Fix `dependent: :restrict_with_exception` not allowing a delete to occur. [Brendan Kilfoil]
|
3
10
|
* Replace `Arel::SelectManager#join_sql` with `Arel::SelectManager#join_sources` as `Arel::Node#joins` accepts AST as well. [Swanand Pagnis]
|
data/README.md
CHANGED
@@ -35,10 +35,10 @@ class CreateCategories < ActiveRecord::Migration
|
|
35
35
|
t.integer :parent_id, :null => true, :index => true
|
36
36
|
t.integer :lft, :null => false, :index => true
|
37
37
|
t.integer :rgt, :null => false, :index => true
|
38
|
-
|
38
|
+
|
39
39
|
# optional fields
|
40
|
-
t.integer :depth, :null => false
|
41
|
-
t.integer :children_count, :null => false
|
40
|
+
t.integer :depth, :null => false, :default => 0
|
41
|
+
t.integer :children_count, :null => false, :default => 0
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -63,13 +63,14 @@ Run `rake rdoc` to generate the API docs and see [CollectiveIdea::Acts::NestedSe
|
|
63
63
|
You can pass various options to `acts_as_nested_set` macro. Configuration options are:
|
64
64
|
|
65
65
|
* `parent_column`: specifies the column name to use for keeping the position integer (default: parent_id)
|
66
|
-
* `left_column`: column name for left
|
67
|
-
* `right_column`: column name for right
|
66
|
+
* `left_column`: column name for left boundary data (default: lft)
|
67
|
+
* `right_column`: column name for right boundary data (default: rgt)
|
68
68
|
* `depth_column`: column name for the depth data default (default: depth)
|
69
69
|
* `scope`: restricts what is to be considered a list. Given a symbol, it'll attach “_id” (if it hasn't been already) and use that as the foreign key restriction. You can also pass an array to scope by multiple attributes. Example: `acts_as_nested_set :scope => [:notable_id, :notable_type]`
|
70
|
-
* `dependent`: behavior for cascading destroy. If set to :destroy, all the child objects are destroyed alongside this object by calling their destroy method. If set to :delete_all (default), all the child objects are deleted without calling their destroy method.
|
70
|
+
* `dependent`: behavior for cascading destroy. If set to :destroy, all the child objects are destroyed alongside this object by calling their destroy method. If set to :delete_all (default), all the child objects are deleted without calling their destroy method. If set to :nullify, all child objects will become orphaned and become roots themselves.
|
71
71
|
* `counter_cache`: adds a counter cache for the number of children. defaults to false. Example: `acts_as_nested_set :counter_cache => :children_count`
|
72
72
|
* `order_column`: on which column to do sorting, by default it is the left_column_name. Example: `acts_as_nested_set :order_column => :position`
|
73
|
+
* `touch`: If set to `true`, then the updated_at timestamp on the ancestors will be set to the current time whenever this object is saved or destroyed (default: false)
|
73
74
|
|
74
75
|
See [CollectiveIdea::Acts::NestedSet::Model::ClassMethods](/lib/awesome_nested_set/model.rb#L26) for a list of class methods and [CollectiveIdea::Acts::NestedSet::Model](lib/awesome_nested_set/model.rb#L13) for a list of instance methods added to acts_as_nested_set models
|
75
76
|
|
@@ -157,7 +158,7 @@ end
|
|
157
158
|
|
158
159
|
To make use of `awesome_nested_set`, your model needs to have 3 fields:
|
159
160
|
`lft`, `rgt`, and `parent_id`. The names of these fields are configurable.
|
160
|
-
You can also have
|
161
|
+
You can also have optional fields, `depth` and `children_count`.
|
161
162
|
|
162
163
|
Create a migration to add fields:
|
163
164
|
|
@@ -167,9 +168,12 @@ class AddNestedToCategories < ActiveRecord::Migration
|
|
167
168
|
def self.up
|
168
169
|
add_column :categories, :parent_id, :integer # Comment this line if your project already has this column
|
169
170
|
# Category.where(parent_id: 0).update_all(parent_id: nil) # Uncomment this line if your project already has :parent_id
|
170
|
-
add_column :categories, :lft
|
171
|
-
add_column :categories, :rgt
|
172
|
-
|
171
|
+
add_column :categories, :lft, :integer
|
172
|
+
add_column :categories, :rgt, :integer
|
173
|
+
|
174
|
+
# optional fields
|
175
|
+
add_column :categories, :depth, :integer
|
176
|
+
add_column :categories, :children_count, :integer
|
173
177
|
|
174
178
|
# This is necessary to update :lft and :rgt columns
|
175
179
|
Category.rebuild!
|
@@ -179,7 +183,10 @@ class AddNestedToCategories < ActiveRecord::Migration
|
|
179
183
|
remove_column :categories, :parent_id
|
180
184
|
remove_column :categories, :lft
|
181
185
|
remove_column :categories, :rgt
|
182
|
-
|
186
|
+
|
187
|
+
# optional fields
|
188
|
+
remove_column :categories, :depth
|
189
|
+
remove_column :categories, :children_count
|
183
190
|
end
|
184
191
|
|
185
192
|
end
|
@@ -206,6 +213,8 @@ Category.rebuild!
|
|
206
213
|
|
207
214
|
Your tree will be converted to a valid nested set. Awesome!
|
208
215
|
|
216
|
+
Note: You can use `Category.rebuild!(false)` to skip model validations when performing the rebuild.
|
217
|
+
|
209
218
|
## View Helper
|
210
219
|
|
211
220
|
The view helper is called #nested_set_options.
|
@@ -32,23 +32,23 @@ module CollectiveIdea #:nodoc:
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def quoted_left_column_name
|
35
|
-
|
35
|
+
model_connection.quote_column_name(left_column_name)
|
36
36
|
end
|
37
37
|
|
38
38
|
def quoted_right_column_name
|
39
|
-
|
39
|
+
model_connection.quote_column_name(right_column_name)
|
40
40
|
end
|
41
41
|
|
42
42
|
def quoted_depth_column_name
|
43
|
-
|
43
|
+
model_connection.quote_column_name(depth_column_name)
|
44
44
|
end
|
45
45
|
|
46
46
|
def quoted_primary_column_name
|
47
|
-
|
47
|
+
model_connection.quote_column_name(primary_column_name)
|
48
48
|
end
|
49
49
|
|
50
50
|
def quoted_parent_column_name
|
51
|
-
|
51
|
+
model_connection.quote_column_name(parent_column_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
def quoted_scope_column_names
|
@@ -56,7 +56,7 @@ module CollectiveIdea #:nodoc:
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def quoted_order_column_name
|
59
|
-
|
59
|
+
model_connection.quote_column_name(order_column)
|
60
60
|
end
|
61
61
|
|
62
62
|
def quoted_primary_key_column_full_name
|
@@ -78,6 +78,10 @@ module CollectiveIdea #:nodoc:
|
|
78
78
|
def quoted_parent_column_full_name
|
79
79
|
"#{quoted_table_name}.#{quoted_parent_column_name}"
|
80
80
|
end
|
81
|
+
|
82
|
+
def model_connection
|
83
|
+
self.is_a?(Class) ? self.connection : self.class.connection
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -3,16 +3,23 @@ module CollectiveIdea #:nodoc:
|
|
3
3
|
module NestedSet #:nodoc:
|
4
4
|
module Model
|
5
5
|
module Transactable
|
6
|
+
class OpenTransactionsIsNotZero < ActiveRecord::StatementInvalid
|
7
|
+
end
|
8
|
+
|
9
|
+
class DeadlockDetected < ActiveRecord::StatementInvalid
|
10
|
+
end
|
6
11
|
|
7
12
|
protected
|
8
13
|
def in_tenacious_transaction(&block)
|
9
14
|
retry_count = 0
|
10
15
|
begin
|
11
16
|
transaction(&block)
|
17
|
+
rescue CollectiveIdea::Acts::NestedSet::Move::ImpossibleMove
|
18
|
+
raise
|
12
19
|
rescue ActiveRecord::StatementInvalid => error
|
13
|
-
raise unless
|
20
|
+
raise OpenTransactionsIsNotZero.new(error.message) unless connection.open_transactions.zero?
|
14
21
|
raise unless error.message =~ /[Dd]eadlock|Lock wait timeout exceeded/
|
15
|
-
raise unless retry_count < 10
|
22
|
+
raise DeadlockDetected.new(error.message) unless retry_count < 10
|
16
23
|
retry_count += 1
|
17
24
|
logger.info "Deadlock detected on retry #{retry_count}, restarting transaction"
|
18
25
|
sleep(rand(retry_count)*0.1) # Aloha protocol
|
@@ -110,9 +110,12 @@ module CollectiveIdea #:nodoc:
|
|
110
110
|
[bound, other_bound]
|
111
111
|
end
|
112
112
|
|
113
|
+
class ImpossibleMove < ActiveRecord::StatementInvalid
|
114
|
+
end
|
115
|
+
|
113
116
|
def prevent_impossible_move
|
114
117
|
if !root && !instance.move_possible?(target)
|
115
|
-
raise
|
118
|
+
raise ImpossibleMove, "Impossible move, target node cannot be inside moved tree."
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
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.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
133
|
+
version: 1.9.3
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
@@ -138,9 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.5.1
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: An awesome nested set implementation for Active Record
|
145
145
|
test_files: []
|
146
|
-
has_rdoc:
|