mongo_nested_set 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -525,82 +525,34 @@ module MongoNestedSet
525
525
  else target.send(parent_column_name)
526
526
  end
527
527
 
528
- # base_class.collection.update({
529
- # left_column_name => { '$gte' => a },
530
- # left_column_name => { '$lte' => b }
531
- # }, {
532
- # '$inc' => { left_column_name => d - b }
533
- # }, :multi => true)
534
- # base_class.collection.update({
535
- # left_column_name => { '$gte' => c },
536
- # left_column_name => { '$lte' => d }
537
- # }, {
538
- # '$inc' => { left_column_name => a - c }
539
- # }, :multi => true)
540
- # base_class.collection.update({
541
- # right_column_name => { '$gte' => a },
542
- # right_column_name => { '$lte' => b }
543
- # }, {
544
- # '$inc' => { right_column_name => d - b }
545
- # }, :multi => true)
546
- # base_class.collection.update({
547
- # right_column_name => { '$gte' => c },
548
- # right_column_name => { '$lte' => d }
549
- # }, {
550
- # '$inc' => { right_column_name => a - c }
551
- # }, :multi => true)
552
- # base_class.collection.update({
553
- # :_id => self.id
554
- # }, {
555
- # parent_column_name => new_parent
556
- # })
557
-
558
- to_update = {}
559
-
560
528
  base_class.find(:all, scoped).each do |node|
561
- to_update_this_node = {}
529
+ node_updates = {}
562
530
  if (a..b).include? node.left
563
- node.send :"#{left_column_name}=", node.left + d - b
531
+ node.update_column left_column_name, node.left + d - b
564
532
  elsif (c..d).include? node.left
565
- node.send :"#{left_column_name}=", node.left + a - c
533
+ node.update_column left_column_name, node.left + a - c
566
534
  end
567
535
  if (a..b).include? node.right
568
- node.send :"#{right_column_name}=", node.right + d - b
536
+ node.update_column right_column_name, node.right + d - b
569
537
  elsif (c..d).include? node.right
570
- node.send :"#{right_column_name}=", node.right + a - c
538
+ node.update_column right_column_name, node.right + a - c
571
539
  end
572
- node.send :"#{parent_column_name}=", new_parent if self.id == node.id
573
- node.save_without_nested_set_callbacks if node.changed?
540
+ node.update_column parent_column_name, new_parent if self.id == node.id
574
541
  end
575
542
 
576
- # self.class.base_class.update_all([
577
- # "#{quoted_left_column_name} = CASE " +
578
- # "WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
579
- # "THEN #{quoted_left_column_name} + :d - :b " +
580
- # "WHEN #{quoted_left_column_name} BETWEEN :c AND :d " +
581
- # "THEN #{quoted_left_column_name} + :a - :c " +
582
- # "ELSE #{quoted_left_column_name} END, " +
583
- # "#{quoted_right_column_name} = CASE " +
584
- # "WHEN #{quoted_right_column_name} BETWEEN :a AND :b " +
585
- # "THEN #{quoted_right_column_name} + :d - :b " +
586
- # "WHEN #{quoted_right_column_name} BETWEEN :c AND :d " +
587
- # "THEN #{quoted_right_column_name} + :a - :c " +
588
- # "ELSE #{quoted_right_column_name} END, " +
589
- # "#{quoted_parent_column_name} = CASE " +
590
- # "WHEN id = :id THEN :new_parent " +
591
- # "ELSE #{quoted_parent_column_name} END",
592
- # {:a => a, :b => b, :c => c, :d => d, :id => self.id, :new_parent => new_parent}
593
- # ], nested_set_scope.proxy_options[:conditions])
594
-
595
543
  target.reload_nested_set if target
596
544
  self.reload_nested_set
597
545
  run_callbacks(:after_move)
598
546
  end
599
547
 
600
- def save_without_nested_set_callbacks
601
- @skip_nested_set_callbacks = true
602
- save!
603
- @skip_nested_set_callbacks = false
548
+ def without_nested_set_callbacks(&block)
549
+ old_value, @skip_nested_set_callbacks = @skip_nested_set_callbacks || false, true
550
+ yield self
551
+ @skip_nested_set_callbacks = old_value
552
+ end
553
+
554
+ def update_column(name, value)
555
+ base_class.collection.update({ :_id => id }, { '$set' => { name => value } })
604
556
  end
605
557
  end
606
558
  end
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongo_nested_set}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Powell", "Brandon Keepers", "Daniel Morrison"]
12
+ s.date = %q{2010-01-12}
13
+ s.description = %q{Port of awesome_nested_set for MongoMapper}
14
+ s.email = %q{fauxparse@gmail.com}
15
+ s.files = [
16
+ ".gitignore",
17
+ "Rakefile",
18
+ "VERSION",
19
+ "init.rb",
20
+ "lib/mongo_nested_set.rb",
21
+ "mongo_nested_set.gemspec",
22
+ "rails/init.rb",
23
+ "test/fixtures/category.rb",
24
+ "test/nested_set_test.rb",
25
+ "test/test_helper.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/fauxparse/mongo_nested_set}
28
+ s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.5}
31
+ s.summary = %q{Port of awesome_nested_set for MongoMapper}
32
+ s.test_files = [
33
+ "test/fixtures/category.rb",
34
+ "test/nested_set_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.6.10"])
44
+ else
45
+ s.add_dependency(%q<mongo_mapper>, [">= 0.6.10"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<mongo_mapper>, [">= 0.6.10"])
49
+ end
50
+ end
51
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Powell
@@ -33,10 +33,12 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
 
35
35
  files:
36
+ - .gitignore
36
37
  - Rakefile
37
38
  - VERSION
38
39
  - init.rb
39
40
  - lib/mongo_nested_set.rb
41
+ - mongo_nested_set.gemspec
40
42
  - rails/init.rb
41
43
  - test/fixtures/category.rb
42
44
  - test/nested_set_test.rb