awesome_nested_set 2.1.5 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 2.1.6
2
+ * Fixed rebuild! when there is a default_scope with order [Adrian Serafin]
3
+ * Testing with stable bundler, ruby 2.0, MySQL and PostgreSQL [Philip Arndt]
4
+ * Optimized move_to for large trees [ericsmith66]
5
+
1
6
  2.1.5
2
7
  * Worked around issues where AR#association wasn't present on Rails 3.0.x. [Philip Arndt]
3
8
  * Adds option 'order_column' which defaults to 'left_column_name'. [gudata]
@@ -181,34 +181,37 @@ module CollectiveIdea #:nodoc:
181
181
  # Rebuilds the left & rights if unset or invalid.
182
182
  # Also very useful for converting from acts_as_tree.
183
183
  def rebuild!(validate_nodes = true)
184
- # Don't rebuild a valid tree.
185
- return true if valid?
186
-
187
- scope = lambda{|node|}
188
- if acts_as_nested_set_options[:scope]
189
- scope = lambda{|node|
190
- scope_column_names.inject(""){|str, column_name|
191
- str << "AND #{connection.quote_column_name(column_name)} = #{connection.quote(node.send(column_name.to_sym))} "
184
+ # default_scope with order may break database queries so we do all operation without scope
185
+ unscoped do
186
+ # Don't rebuild a valid tree.
187
+ return true if valid?
188
+
189
+ scope = lambda{|node|}
190
+ if acts_as_nested_set_options[:scope]
191
+ scope = lambda{|node|
192
+ scope_column_names.inject(""){|str, column_name|
193
+ str << "AND #{connection.quote_column_name(column_name)} = #{connection.quote(node.send(column_name.to_sym))} "
194
+ }
192
195
  }
193
- }
194
- end
195
- indices = {}
196
-
197
- set_left_and_rights = lambda do |node|
198
- # set left
199
- node[left_column_name] = indices[scope.call(node)] += 1
200
- # find
201
- where(["#{quoted_parent_column_full_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each{|n| set_left_and_rights.call(n) }
202
- # set right
203
- node[right_column_name] = indices[scope.call(node)] += 1
204
- node.save!(:validate => validate_nodes)
205
- end
196
+ end
197
+ indices = {}
198
+
199
+ set_left_and_rights = lambda do |node|
200
+ # set left
201
+ node[left_column_name] = indices[scope.call(node)] += 1
202
+ # find
203
+ where(["#{quoted_parent_column_full_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each{|n| set_left_and_rights.call(n) }
204
+ # set right
205
+ node[right_column_name] = indices[scope.call(node)] += 1
206
+ node.save!(:validate => validate_nodes)
207
+ end
206
208
 
207
- # Find root node(s)
208
- root_nodes = where("#{quoted_parent_column_full_name} IS NULL").order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each do |root_node|
209
- # setup index for this scope
210
- indices[scope.call(root_node)] ||= 0
211
- set_left_and_rights.call(root_node)
209
+ # Find root node(s)
210
+ root_nodes = where("#{quoted_parent_column_full_name} IS NULL").order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each do |root_node|
211
+ # setup index for this scope
212
+ indices[scope.call(root_node)] ||= 0
213
+ set_left_and_rights.call(root_node)
214
+ end
212
215
  end
213
216
  end
214
217
 
@@ -652,7 +655,27 @@ module CollectiveIdea #:nodoc:
652
655
  else target[parent_column_name]
653
656
  end
654
657
 
655
- self.nested_set_scope.update_all([
658
+ where_statement = ["not (#{quoted_left_column_name} = CASE " +
659
+ "WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
660
+ "THEN #{quoted_left_column_name} + :d - :b " +
661
+ "WHEN #{quoted_left_column_name} BETWEEN :c AND :d " +
662
+ "THEN #{quoted_left_column_name} + :a - :c " +
663
+ "ELSE #{quoted_left_column_name} END AND " +
664
+ "#{quoted_right_column_name} = CASE " +
665
+ "WHEN #{quoted_right_column_name} BETWEEN :a AND :b " +
666
+ "THEN #{quoted_right_column_name} + :d - :b " +
667
+ "WHEN #{quoted_right_column_name} BETWEEN :c AND :d " +
668
+ "THEN #{quoted_right_column_name} + :a - :c " +
669
+ "ELSE #{quoted_right_column_name} END AND " +
670
+ "#{quoted_parent_column_name} = CASE " +
671
+ "WHEN #{self.class.base_class.primary_key} = :id THEN :new_parent " +
672
+ "ELSE #{quoted_parent_column_name} END)" ,
673
+ {:a => a, :b => b, :c => c, :d => d, :id => self.id, :new_parent => new_parent} ]
674
+
675
+
676
+
677
+
678
+ self.nested_set_scope.where(*where_statement).update_all([
656
679
  "#{quoted_left_column_name} = CASE " +
657
680
  "WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
658
681
  "THEN #{quoted_left_column_name} + :d - :b " +
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '2.1.5' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '2.1.6' 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: 2.1.5
4
+ version: 2.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-26 00:00:00.000000000 Z
14
+ date: 2013-02-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ~>
38
38
  - !ruby/object:Gem::Version
39
- version: '2.8'
39
+ version: '2.12'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +44,39 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '2.8'
47
+ version: '2.12'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '10'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '10'
64
+ - !ruby/object:Gem::Dependency
65
+ name: combustion
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 0.3.3
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: 0.3.3
48
80
  description: An awesome nested set implementation for Active Record
49
81
  email: info@collectiveidea.com
50
82
  executables: []
@@ -60,7 +92,8 @@ files:
60
92
  - README.rdoc
61
93
  - CHANGELOG
62
94
  homepage: http://github.com/collectiveidea/awesome_nested_set
63
- licenses: []
95
+ licenses:
96
+ - MIT
64
97
  post_install_message:
65
98
  rdoc_options:
66
99
  - --main
@@ -83,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
116
  version: '0'
84
117
  requirements: []
85
118
  rubyforge_project:
86
- rubygems_version: 1.8.24
119
+ rubygems_version: 1.8.25
87
120
  signing_key:
88
121
  specification_version: 3
89
122
  summary: An awesome nested set implementation for Active Record
90
123
  test_files: []
91
- has_rdoc: