simple_nested_set 0.0.29 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_nested_set/act_macro.rb +2 -2
- data/lib/simple_nested_set/move/by_attributes.rb +2 -2
- data/lib/simple_nested_set/move/to_target.rb +2 -2
- data/lib/simple_nested_set/nested_set.rb +4 -4
- data/lib/simple_nested_set/patches/arel_table_initialization.rb +1 -1
- data/lib/simple_nested_set/version.rb +1 -1
- metadata +4 -4
@@ -16,7 +16,7 @@ module SimpleNestedSet
|
|
16
16
|
after_save lambda { |r| r.nested_set.save! }
|
17
17
|
|
18
18
|
belongs_to :parent, :class_name => self.name
|
19
|
-
has_many :children, :foreign_key => :parent_id, :class_name => self.name
|
19
|
+
has_many :children, :foreign_key => :parent_id, :class_name => self.name, :order => :lft
|
20
20
|
|
21
21
|
default_scope :order => :lft
|
22
22
|
|
@@ -28,4 +28,4 @@ module SimpleNestedSet
|
|
28
28
|
included_modules.include?(SimpleNestedSet::InstanceMethods)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -36,7 +36,7 @@ module SimpleNestedSet
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def move_by_parent_id?
|
39
|
-
|
39
|
+
node.parent_id_changed?
|
40
40
|
end
|
41
41
|
|
42
42
|
def move_by_left_id
|
@@ -52,7 +52,7 @@ module SimpleNestedSet
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def parent_id
|
55
|
-
attributes[:parent_id]
|
55
|
+
attributes[:parent_id] == 0 ? nil : attributes[:parent_id]
|
56
56
|
end
|
57
57
|
|
58
58
|
def left_id
|
@@ -71,7 +71,7 @@ module SimpleNestedSet
|
|
71
71
|
when :child ; target.rgt
|
72
72
|
when :left ; target.lft
|
73
73
|
when :right ; target.rgt + 1
|
74
|
-
when :root ; roots.empty? ? 1 : roots.last.rgt + 1
|
74
|
+
when :root ; roots.empty? ? 1 : roots.where('id <> ?', node.id).last.rgt + 1
|
75
75
|
end
|
76
76
|
bound > node.rgt ? bound - 1 : bound
|
77
77
|
end
|
@@ -91,4 +91,4 @@ module SimpleNestedSet
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
end
|
94
|
+
end
|
@@ -25,7 +25,7 @@ module SimpleNestedSet
|
|
25
25
|
|
26
26
|
def extract_attributes!(attributes)
|
27
27
|
attributes.slice(*SimpleNestedSet::ATTRIBUTES).tap do
|
28
|
-
attributes.except!(*(SimpleNestedSet::ATTRIBUTES - [:path]))
|
28
|
+
attributes.except!(*(SimpleNestedSet::ATTRIBUTES - [:path, :parent, :parent_id]))
|
29
29
|
end if attributes.respond_to?(:slice)
|
30
30
|
end
|
31
31
|
end
|
@@ -40,14 +40,15 @@ module SimpleNestedSet
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def save!
|
43
|
-
attributes = node.instance_variable_get(:@_nested_set_attributes)
|
43
|
+
attributes = node.instance_variable_get(:@_nested_set_attributes) || {}
|
44
44
|
node.instance_variable_set(:@_nested_set_attributes, nil)
|
45
|
+
attributes.merge!(:parent_id => node.parent_id) if node.parent_id_changed?
|
45
46
|
|
46
47
|
if self.class.move_after_save
|
47
48
|
move_by_attributes(attributes) unless attributes.blank?
|
48
49
|
denormalize!
|
49
50
|
elsif attributes
|
50
|
-
attributes.each do |key, value|
|
51
|
+
attributes.except(:parent_id).each do |key, value|
|
51
52
|
node.update_attribute(key, value)
|
52
53
|
end
|
53
54
|
end
|
@@ -100,7 +101,6 @@ module SimpleNestedSet
|
|
100
101
|
def populate_associations(nodes)
|
101
102
|
node.children.target = nodes.select do |child|
|
102
103
|
next unless child.parent_id == node.id
|
103
|
-
nodes.delete(child)
|
104
104
|
child.nested_set.populate_associations(nodes)
|
105
105
|
child.parent = node
|
106
106
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_nested_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 35
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 30
|
10
|
+
version: 0.0.30
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-02-23 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|