simple_nested_set 0.0.2 → 0.0.3
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.
@@ -14,7 +14,7 @@ module SimpleNestedSet
|
|
14
14
|
before_destroy lambda { |r| r.nested_set.prune_branch }
|
15
15
|
|
16
16
|
belongs_to :parent, :class_name => self.name
|
17
|
-
has_many :children, :foreign_key => :parent_id, :class_name => self.
|
17
|
+
has_many :children, :foreign_key => :parent_id, :class_name => class_of_active_record_descendant(self).name
|
18
18
|
|
19
19
|
default_scope :order => :lft
|
20
20
|
|
@@ -19,7 +19,7 @@ module SimpleNestedSet
|
|
19
19
|
def initialize(node, attributes)
|
20
20
|
@node, @attributes = node, attributes
|
21
21
|
normalize_attributes!
|
22
|
-
protect_inconsistent_move!
|
22
|
+
protect_inconsistent_move!
|
23
23
|
end
|
24
24
|
|
25
25
|
def perform
|
@@ -39,14 +39,14 @@ module SimpleNestedSet
|
|
39
39
|
attributes.each { |key, value| attributes[key] = nil if value == 'null' }
|
40
40
|
|
41
41
|
# if left_id is given but blank, set right_id to leftmost sibling
|
42
|
-
if
|
43
|
-
attributes[:right_id] = siblings.first.id
|
44
|
-
end
|
42
|
+
attributes[:right_id] = siblings.first.id if blank_given?(:left_id) && siblings.any?
|
45
43
|
|
46
44
|
# if right_id is given but blank, set left_id to rightmost sibling
|
47
|
-
if
|
48
|
-
|
49
|
-
|
45
|
+
attributes[:left_id] = siblings.last.id if blank_given?(:right_id) && siblings.any?
|
46
|
+
end
|
47
|
+
|
48
|
+
def blank_given?(key)
|
49
|
+
attributes.has_key?(key) && attributes[key].blank? && siblings.any?
|
50
50
|
end
|
51
51
|
|
52
52
|
def siblings
|
@@ -14,8 +14,8 @@ module SimpleNestedSet
|
|
14
14
|
impossible_move!("A node can't be moved to a different scope") if target && !nested_set.same_scope?(target)
|
15
15
|
end
|
16
16
|
|
17
|
-
def protect_inconsistent_move!
|
18
|
-
left = nested_set.find(left_id)
|
17
|
+
def protect_inconsistent_move!
|
18
|
+
left = nested_set.find(left_id) if left_id
|
19
19
|
right = nested_set.find(right_id) if right_id
|
20
20
|
|
21
21
|
if left && right && (!left.right_sibling || left.right_sibling.id != right_id)
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|