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 +4 -4
- data/CHANGELOG +2 -0
- data/lib/awesome_nested_set/awesome_nested_set.rb +5 -4
- data/lib/awesome_nested_set/model.rb +11 -4
- data/lib/awesome_nested_set/model/movable.rb +2 -2
- data/lib/awesome_nested_set/model/prunable.rb +2 -0
- data/lib/awesome_nested_set/move.rb +7 -7
- data/lib/awesome_nested_set/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d1c0885abe0d301749e9c918588554824172ece
|
4
|
+
data.tar.gz: 6d2fb2d4d781491b9fc76812d822d973308f1a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 994a05b6c6d17b97a7ab365cf1a3a77e3fbde00a1bdd10da1f00f3bf6d31f09f78de81ed56ca1891d92b8f27e7befc22865215a1a3c3fe239add0d5ef1c2f19d
|
7
|
+
data.tar.gz: d7c1929abfb91c0f5f78f1a02782c90b37da7c2c8172a891a83411e392255f6d778e1ab3f022c3fa8a5526d0beb0372186b7b377ca66dd24bae58b97ee17da26
|
data/CHANGELOG
CHANGED
@@ -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(
|
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
|
-
|
88
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
109
|
-
when :left
|
110
|
-
when :right
|
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
|
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
|
+
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-
|
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
|
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
|