awesome_nested_set 3.0.0.rc.1 → 3.0.0.rc.2

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: 559dfc3c4e84219413936644a4f9562bb5b99f7e
4
- data.tar.gz: 94ab72b3cc301118a120e63a147dc002664c5ca3
3
+ metadata.gz: 5d1c0885abe0d301749e9c918588554824172ece
4
+ data.tar.gz: 6d2fb2d4d781491b9fc76812d822d973308f1a28
5
5
  SHA512:
6
- metadata.gz: 75ca6ea8548d4099e7879832d4b66035dcd825adf027eb05f662ea3651bf63e32957f5e9a1aa5a98d47a1a889d697ed10c63ef0dc943bc0f8908c43279921da3
7
- data.tar.gz: 3b678935e580e09010e66cc45114e01d103bb4b4aa726bef1885f969d1c54fd05d9bafc67b28db3af677f81e0749439de2dfa3b765d4785d453272045d3c10a3
6
+ metadata.gz: 994a05b6c6d17b97a7ab365cf1a3a77e3fbde00a1bdd10da1f00f3bf6d31f09f78de81ed56ca1891d92b8f27e7befc22865215a1a3c3fe239add0d5ef1c2f19d
7
+ data.tar.gz: d7c1929abfb91c0f5f78f1a02782c90b37da7c2c8172a891a83411e392255f6d778e1ab3f022c3fa8a5526d0beb0372186b7b377ca66dd24bae58b97ee17da26
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ * Modified associate_parents to add child objects to the parent#children collection [Tiago Moraes]
2
+
1
3
  2.1.6
2
4
  * Fixed rebuild! when there is a default_scope with order [Adrian Serafin]
3
5
  * Testing with stable bundler, ruby 2.0, MySQL and PostgreSQL [Philip Arndt]
@@ -75,17 +75,18 @@ module CollectiveIdea #:nodoc:
75
75
  has_many_children_options = {
76
76
  :class_name => self.base_class.to_s,
77
77
  :foreign_key => parent_column_name,
78
- :order => quoted_order_column_name,
79
78
  :inverse_of => (:parent unless acts_as_nested_set_options[:polymorphic]),
80
79
  }
81
80
 
82
81
  # Add callbacks, if they were supplied.. otherwise, we don't want them.
83
82
  [:before_add, :after_add, :before_remove, :after_remove].each do |ar_callback|
84
- has_many_children_options.update(ar_callback => acts_as_nested_set_options[ar_callback]) if acts_as_nested_set_options[ar_callback]
83
+ has_many_children_options.update(
84
+ ar_callback => acts_as_nested_set_options[ar_callback]
85
+ ) if acts_as_nested_set_options[ar_callback]
85
86
  end
86
87
 
87
- order_condition = has_many_children_options.delete(:order)
88
- has_many :children, -> { order(order_condition) }, has_many_children_options
88
+ has_many :children, -> { order(quoted_order_column_name) },
89
+ has_many_children_options
89
90
  end
90
91
 
91
92
  def acts_as_nested_set_relate_parent!
@@ -34,11 +34,18 @@ module CollectiveIdea #:nodoc:
34
34
 
35
35
  if !association.loaded? && parent
36
36
  association.target = parent
37
- association.set_inverse_instance(parent)
37
+ add_to_inverse_association(association, parent)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
+ def add_to_inverse_association(association, record)
43
+ inverse_reflection = association.send(:inverse_reflection_for, record)
44
+ inverse = record.association(inverse_reflection.name)
45
+ inverse.target << association.owner
46
+ inverse.loaded!
47
+ end
48
+
42
49
  def children_of(parent_id)
43
50
  where arel_table[parent_column_name].eq(parent_id)
44
51
  end
@@ -134,7 +141,7 @@ module CollectiveIdea #:nodoc:
134
141
  end
135
142
  end
136
143
 
137
- self.class.nested_set_scope options
144
+ self.class.base_class.nested_set_scope options
138
145
  end
139
146
 
140
147
  def to_text
@@ -199,10 +206,10 @@ module CollectiveIdea #:nodoc:
199
206
  )
200
207
  end
201
208
 
202
- def reload_target(target)
209
+ def reload_target(target, position)
203
210
  if target.is_a? self.class.base_class
204
211
  target.reload
205
- else
212
+ elsif position != :root
206
213
  nested_set_scope.find(target)
207
214
  end
208
215
  end
@@ -52,7 +52,7 @@ module CollectiveIdea #:nodoc:
52
52
 
53
53
  # Move the node to root nodes
54
54
  def move_to_root
55
- move_to_right_of(root)
55
+ move_to self, :root
56
56
  end
57
57
 
58
58
  # Order children in a nested set by an attribute
@@ -91,7 +91,7 @@ module CollectiveIdea #:nodoc:
91
91
 
92
92
  run_callbacks :move do
93
93
  in_tenacious_transaction do
94
- target = reload_target(target)
94
+ target = reload_target(target, position)
95
95
  self.reload_nested_set
96
96
 
97
97
  Move.new(target, position, self).move
@@ -30,6 +30,8 @@ module CollectiveIdea #:nodoc:
30
30
  model.skip_before_destroy = true
31
31
  model.destroy
32
32
  end
33
+ elsif acts_as_nested_set_options[:dependent] == :restrict_with_exception
34
+ raise ActiveRecord::DeleteRestrictionError.new(:children) unless leaf?
33
35
  else
34
36
  descendants.delete_all
35
37
  end
@@ -80,10 +80,9 @@ module CollectiveIdea #:nodoc:
80
80
 
81
81
  def new_parent
82
82
  case position
83
- when :child
84
- target.id
85
- else
86
- target[parent_column_name]
83
+ when :child then target.id
84
+ when :root then nil
85
+ else target[parent_column_name]
87
86
  end
88
87
  end
89
88
 
@@ -105,9 +104,10 @@ module CollectiveIdea #:nodoc:
105
104
 
106
105
  def target_bound
107
106
  case position
108
- when :child; right(target)
109
- when :left; left(target)
110
- when :right; right(target) + 1
107
+ when :child then right(target)
108
+ when :left then left(target)
109
+ when :right then right(target) + 1
110
+ when :root then nested_set_scope.pluck(right_column_name).max + 1
111
111
  else raise ActiveRecord::ActiveRecordError, "Position should be :child, :left, :right or :root ('#{position}' received)."
112
112
  end
113
113
  end
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '3.0.0.rc.1' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '3.0.0.rc.2' 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.1
4
+ version: 3.0.0.rc.2
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: 2013-08-01 00:00:00.000000000 Z
13
+ date: 2013-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: 1.3.1
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.0.3
135
+ rubygems_version: 2.1.0
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: An awesome nested set implementation for Active Record