simple_nested_set 0.0.17 → 0.0.18

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,24 +14,49 @@ module SimpleNestedSet
14
14
  end
15
15
 
16
16
  def perform
17
+ move_by_parent_id if move_by_parent_id?
18
+
19
+ # if left_id is given but blank, set right_id to leftmost sibling
20
+ attributes[:right_id] = siblings.first.id if blank_given?(:left_id) && siblings.any?
21
+
22
+ # if right_id is given but blank, set left_id to rightmost sibling
23
+ attributes[:left_id] = siblings.last.id if blank_given?(:right_id) && siblings.any?
24
+
17
25
  if path && node.path_changed?
18
26
  node.move_to_path(path)
19
- elsif attributes.key?(:left_id) && left_id != node.id && (left_id || !parent_id)
20
- node.move_to_right_of(left_id)
21
- elsif attributes.key?(:right_id) && right_id != node.id && (right_id || !parent_id)
22
- node.move_to_left_of(right_id)
23
- elsif attributes.key?(:parent_id) && parent_id != node.parent_id
24
- node.move_to_child_of(parent_id)
25
- if attributes.key?(:left_id) && left_id != node.id
26
- node.move_to_right_of(left_id)
27
- elsif attributes.key?(:right_id) && right_id != node.id
28
- node.move_to_left_of(right_id)
29
- end
27
+ elsif move_by_left_id?
28
+ move_by_left_id
29
+ elsif move_by_right_id?
30
+ move_by_right_id
30
31
  end
31
32
  end
32
33
 
33
34
  protected
34
35
 
36
+ def move_by_left_id?
37
+ attributes.key?(:left_id) && left_id != node.id
38
+ end
39
+
40
+ def move_by_right_id?
41
+ attributes.key?(:right_id) && right_id != node.id
42
+ end
43
+
44
+ def move_by_parent_id?
45
+ attributes.key?(:parent_id) && parent_id != node.parent_id
46
+ end
47
+
48
+ def move_by_left_id
49
+ node.move_to_right_of(left_id)
50
+ end
51
+
52
+ def move_by_right_id
53
+ node.move_to_left_of(right_id)
54
+ end
55
+
56
+ def move_by_parent_id
57
+ node.move_to_child_of(parent_id)
58
+ end
59
+
35
60
  def parent_id
36
61
  attributes[:parent_id].blank? ? nil : attributes[:parent_id].to_i
37
62
  end
@@ -56,11 +81,6 @@ module SimpleNestedSet
56
81
  attributes[:"#{key}_id"] = attributes.delete(key).id if attributes.key?(key)
57
82
  end
58
83
 
59
- # if left_id is given but blank, set right_id to leftmost sibling
60
- attributes[:right_id] = siblings.first.id if blank_given?(:left_id) && siblings.any?
61
-
62
- # if right_id is given but blank, set left_id to rightmost sibling
63
- attributes[:left_id] = siblings.last.id if blank_given?(:right_id) && siblings.any?
64
84
  end
65
85
 
66
86
  def blank_given?(key)
@@ -1,3 +1,3 @@
1
1
  module SimpleNestedSet
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  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: 61
4
+ hash: 59
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 17
10
- version: 0.0.17
9
+ - 18
10
+ version: 0.0.18
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-11-02 00:00:00 +01:00
18
+ date: 2010-11-04 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -104,6 +104,20 @@ dependencies:
104
104
  version: "0"
105
105
  type: :development
106
106
  version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: ruby-debug
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :development
120
+ version_requirements: *id007
107
121
  description: simple_nested_set allows to easily handle nested sets in ActiveRecord
108
122
  email: svenfuchs@artweb-design.de
109
123
  executables: []