awesome_nested_set 2.0.1 → 2.0.2

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,12 @@
1
+ 2.0.2
2
+ * Fixed deprecation warning under Rails 3.1 [Philip Arndt]
3
+ * Converted Test::Unit matchers to RSpec. [Uģis Ozols]
4
+ * Added inverse_of to associations to improve performance rendering trees. [Sergio Cambra]
5
+ * Added row locking and fixed some race conditions. [Markus J. Q. Roberts]
6
+
7
+ 2.0.1
8
+ * Fixed a bug with move_to not using nested_set_scope [Andreas Sekine]
9
+
1
10
  2.0.0.pre
2
11
  * Expect Rails 3
3
12
  * Changed how callbacks work. Returning false in a before_move action does not block save operations. Use a validation or exception in the callback if you need that.
@@ -39,7 +39,7 @@ Enable the nested set functionality by declaring acts_as_nested_set on your mode
39
39
  acts_as_nested_set
40
40
  end
41
41
 
42
- Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::Model::SingletonMethods for more info.
42
+ Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet for more info.
43
43
 
44
44
  == Conversion from other trees
45
45
 
@@ -51,8 +51,8 @@ module CollectiveIdea #:nodoc:
51
51
  options[:scope] = "#{options[:scope]}_id".intern
52
52
  end
53
53
 
54
- write_inheritable_attribute :acts_as_nested_set_options, options
55
- class_inheritable_reader :acts_as_nested_set_options
54
+ class_attribute :acts_as_nested_set_options
55
+ self.acts_as_nested_set_options = options
56
56
 
57
57
  include CollectiveIdea::Acts::NestedSet::Model
58
58
  include Columns
@@ -60,9 +60,11 @@ module CollectiveIdea #:nodoc:
60
60
 
61
61
  belongs_to :parent, :class_name => self.base_class.to_s,
62
62
  :foreign_key => parent_column_name,
63
- :counter_cache => options[:counter_cache]
63
+ :counter_cache => options[:counter_cache],
64
+ :inverse_of => :children
64
65
  has_many :children, :class_name => self.base_class.to_s,
65
- :foreign_key => parent_column_name, :order => quoted_left_column_name
66
+ :foreign_key => parent_column_name, :order => quoted_left_column_name,
67
+ :inverse_of => :parent
66
68
 
67
69
  attr_accessor :skip_before_destroy
68
70
 
@@ -88,7 +90,7 @@ module CollectiveIdea #:nodoc:
88
90
  scope :roots, where(parent_column_name => nil).order(quoted_left_column_name)
89
91
  scope :leaves, where("#{quoted_right_column_name} - #{quoted_left_column_name} = 1").order(quoted_left_column_name)
90
92
 
91
- define_callbacks :move, :terminator => "result == false"
93
+ define_model_callbacks :move
92
94
  end
93
95
 
94
96
  module Model
@@ -382,8 +384,8 @@ module CollectiveIdea #:nodoc:
382
384
  # All nested set queries should use this nested_set_scope, which performs finds on
383
385
  # the base ActiveRecord class, using the :scope declared in the acts_as_nested_set
384
386
  # declaration.
385
- def nested_set_scope
386
- options = {:order => quoted_left_column_name}
387
+ def nested_set_scope(options = {})
388
+ options = {:order => quoted_left_column_name}.merge(options)
387
389
  scopes = Array(acts_as_nested_set_options[:scope])
388
390
  options[:conditions] = scopes.inject({}) do |conditions,attr|
389
391
  conditions.merge attr => self[attr]
@@ -406,7 +408,8 @@ module CollectiveIdea #:nodoc:
406
408
 
407
409
  # on creation, set automatically lft and rgt to the end of the tree
408
410
  def set_default_left_and_right
409
- maxright = nested_set_scope.maximum(right_column_name) || 0
411
+ highest_right_row = nested_set_scope(:order => "#{quoted_right_column_name} desc").find(:first, :limit => 1,:lock => true )
412
+ maxright = highest_right_row ? highest_right_row[right_column_name] : 0
410
413
  # adds the new node to the right of all existing nodes
411
414
  self[left_column_name] = maxright + 1
412
415
  self[right_column_name] = maxright + 2
@@ -490,6 +493,11 @@ module CollectiveIdea #:nodoc:
490
493
  # so sorting puts both the intervals and their boundaries in order
491
494
  a, b, c, d = [self[left_column_name], self[right_column_name], bound, other_bound].sort
492
495
 
496
+ # select the rows in the model between a and d, and apply a lock
497
+ self.class.base_class.select('id').lock(true).where(
498
+ ["#{quoted_left_column_name} >= :a and #{quoted_right_column_name} <= :d", {:a => a, :d => d}]
499
+ )
500
+
493
501
  new_parent = case position
494
502
  when :child; target.id
495
503
  when :root; nil
@@ -561,4 +569,4 @@ module CollectiveIdea #:nodoc:
561
569
 
562
570
  end
563
571
  end
564
- end
572
+ end
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '2.0.1' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '2.0.2' unless defined?(::AwesomeNestedSet::VERSION)
3
3
  end
metadata CHANGED
@@ -1,18 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_set
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease:
5
- version: 2.0.1
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 2
10
+ version: 2.0.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - Brandon Keepers
9
14
  - Daniel Morrison
15
+ - Philip Arndt
10
16
  autorequire:
11
17
  bindir: bin
12
18
  cert_chain: []
13
19
 
14
- date: 2011-06-16 00:00:00 -04:00
15
- default_executable:
20
+ date: 2011-09-06 00:00:00 Z
16
21
  dependencies:
17
22
  - !ruby/object:Gem::Dependency
18
23
  name: activerecord
@@ -22,6 +27,11 @@ dependencies:
22
27
  requirements:
23
28
  - - ">="
24
29
  - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 0
25
35
  version: 3.0.0
26
36
  type: :runtime
27
37
  version_requirements: *id001
@@ -41,7 +51,6 @@ files:
41
51
  - MIT-LICENSE
42
52
  - README.rdoc
43
53
  - CHANGELOG
44
- has_rdoc: true
45
54
  homepage: http://github.com/collectiveidea/awesome_nested_set
46
55
  licenses: []
47
56
 
@@ -58,17 +67,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
67
  requirements:
59
68
  - - ">="
60
69
  - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
61
73
  version: "0"
62
74
  required_rubygems_version: !ruby/object:Gem::Requirement
63
75
  none: false
64
76
  requirements:
65
77
  - - ">="
66
78
  - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
67
82
  version: "0"
68
83
  requirements: []
69
84
 
70
85
  rubyforge_project:
71
- rubygems_version: 1.5.2
86
+ rubygems_version: 1.8.10
72
87
  signing_key:
73
88
  specification_version: 3
74
89
  summary: An awesome nested set implementation for Active Record