awesome_nested_set 3.0.0.rc.4 → 3.0.0.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/awesome_nested_set/model.rb +28 -3
- data/lib/awesome_nested_set/model/movable.rb +1 -2
- data/lib/awesome_nested_set/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9af145388371e47258be0fb9ed3c46ea172a6c3b
|
4
|
+
data.tar.gz: 4273003fd7e7fc00b0a5758001f1cc92af41ffeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035d190dd06666e3fe5d01a36c70223b5150b27d21df6d3bcec5e5923180bde66090eee1f41263747b662f5d6b690aa55d509d8a14209e1dc0831d8424a8ff62
|
7
|
+
data.tar.gz: 99c75707c323da2add1d619c652fae8357396c75c3034a4c9dca92a359a24ed278e0501adf775b007d14e63a3d1c1c4155e1ed3b94f8ce84b756ed2c7a29507a
|
@@ -190,10 +190,35 @@ module CollectiveIdea #:nodoc:
|
|
190
190
|
|
191
191
|
in_tenacious_transaction do
|
192
192
|
reload
|
193
|
-
|
194
|
-
|
193
|
+
update_depth(level)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def set_depth_for_self_and_descendants!
|
198
|
+
return unless has_depth_column?
|
199
|
+
|
200
|
+
in_tenacious_transaction do
|
201
|
+
reload
|
202
|
+
self_and_descendants.select(primary_column_name).lock(true)
|
203
|
+
old_depth = self[depth_column_name] || 0
|
204
|
+
new_depth = level
|
205
|
+
update_depth(new_depth)
|
206
|
+
change_descendants_depth!(new_depth - old_depth)
|
207
|
+
new_depth
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def update_depth(depth)
|
212
|
+
nested_set_scope.primary_key_scope(primary_id).
|
213
|
+
update_all(["#{quoted_depth_column_name} = ?", depth])
|
214
|
+
self[depth_column_name] = depth
|
215
|
+
end
|
216
|
+
|
217
|
+
def change_descendants_depth!(diff)
|
218
|
+
if !leaf? && diff != 0
|
219
|
+
sign = "++-"[diff <=> 0]
|
220
|
+
descendants.update_all("#{quoted_depth_column_name} = #{quoted_depth_column_name} #{sign} #{diff.abs}")
|
195
221
|
end
|
196
|
-
self[depth_column_name] = self.level
|
197
222
|
end
|
198
223
|
|
199
224
|
def set_default_left_and_right
|
@@ -104,8 +104,7 @@ module CollectiveIdea #:nodoc:
|
|
104
104
|
|
105
105
|
def after_move_to(target, position)
|
106
106
|
target.reload_nested_set if target
|
107
|
-
self.
|
108
|
-
self.descendants.each(&:save)
|
107
|
+
self.set_depth_for_self_and_descendants!
|
109
108
|
self.reload_nested_set
|
110
109
|
end
|
111
110
|
|
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.0.rc.
|
4
|
+
version: 3.0.0.rc.5
|
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: 2014-
|
13
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|