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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b906a0322b3f2d297483d2ba0b15ff50388291a6
4
- data.tar.gz: 350093eb665d7ae7c23de6338d0f1793c11d8e8a
3
+ metadata.gz: 9af145388371e47258be0fb9ed3c46ea172a6c3b
4
+ data.tar.gz: 4273003fd7e7fc00b0a5758001f1cc92af41ffeb
5
5
  SHA512:
6
- metadata.gz: 6e90aeca23cb8729cccbf9b87f47176363fc009797eb0ec929823093ebdcd2a4c7dfd590bb2aee131defb15b0de8780a32d5ade6ad0e8de6c2897a7522c5ae84
7
- data.tar.gz: c09e4c671b3c45e7092ccde2c5c9f0e865fc6748cc85433350f342b3e5f83cf0737459ff6f15cabc989afb78df53198a5beba908c4cf5a9afd7672e75e76491a
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
- nested_set_scope.primary_key_scope(primary_id).
194
- update_all(["#{quoted_depth_column_name} = ?", level])
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.set_depth!
108
- self.descendants.each(&:save)
107
+ self.set_depth_for_self_and_descendants!
109
108
  self.reload_nested_set
110
109
  end
111
110
 
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '3.0.0.rc.4' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '3.0.0.rc.5' unless defined?(::AwesomeNestedSet::VERSION)
3
3
  end
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
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-04-30 00:00:00.000000000 Z
13
+ date: 2014-05-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord