simple_nested_set 0.0.18 → 0.0.19

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.
@@ -26,7 +26,7 @@ module SimpleNestedSet
26
26
  end
27
27
 
28
28
  def without_node(id)
29
- where(arel_table[:id].not_eq(id))
29
+ where(arel_table[:id].not_eq(id)).order(:lft)
30
30
  end
31
31
 
32
32
  def without_parent
@@ -34,27 +34,27 @@ module SimpleNestedSet
34
34
  end
35
35
 
36
36
  def with_parent(parent_id)
37
- where(:parent_id => parent_id)
37
+ where(:parent_id => parent_id).order(:lft)
38
38
  end
39
39
 
40
40
  def with_ancestors(lft, rgt)
41
- where(arel_table[:lft].lt(lft).and(arel_table[:rgt].gt(rgt)))
41
+ where(arel_table[:lft].lt(lft).and(arel_table[:rgt].gt(rgt))).order(:lft)
42
42
  end
43
43
 
44
44
  def with_descendants(lft, rgt)
45
- where(arel_table[:lft].gt(lft).and(arel_table[:rgt].lt(rgt)))
45
+ where(arel_table[:lft].gt(lft).and(arel_table[:rgt].lt(rgt))).order(:lft)
46
46
  end
47
47
 
48
48
  def with_left_sibling(lft)
49
- where(:rgt => lft - 1)
49
+ where(:rgt => lft - 1).order(:lft)
50
50
  end
51
51
 
52
52
  def with_right_sibling(rgt)
53
- where(:lft => rgt + 1)
53
+ where(:lft => rgt + 1).order(:lft)
54
54
  end
55
55
 
56
56
  def with_leaves
57
- where("#{arel_table[:lft].to_sql} = #{arel_table[:rgt].to_sql} - 1")
57
+ where("#{arel_table[:lft].to_sql} = #{arel_table[:rgt].to_sql} - 1").order(:lft)
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -155,21 +155,23 @@ module SimpleNestedSet
155
155
  move_to_right_of(right_sibling) if right_sibling
156
156
  end
157
157
 
158
- # Move the node to the left of another node
158
+ # Move the node to the left of another node. If this other node is nil then
159
+ # this means the node is to be made the rightmost sibling.
159
160
  def move_to_left_of(node)
160
161
  if node
161
162
  nested_set.move_to(node, :left)
162
- elsif left_most = siblings.first
163
- move_to_right_of(left_most)
163
+ elsif right_most = siblings.last
164
+ move_to_right_of(right_most)
164
165
  end
165
166
  end
166
167
 
167
- # Move the node to the left of another node
168
+ # Move the node to the left of another node. If this other node is nil then
169
+ # this means the node is to be made the leftmost sibling.
168
170
  def move_to_right_of(node)
169
171
  if node
170
172
  nested_set.move_to(node, :right)
171
- elsif right_most = siblings.last
172
- move_to_left_of(right_most)
173
+ elsif left_most = siblings.first
174
+ move_to_left_of(left_most)
173
175
  end
174
176
  end
175
177
 
@@ -16,12 +16,6 @@ module SimpleNestedSet
16
16
  def perform
17
17
  move_by_parent_id if move_by_parent_id?
18
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
-
25
19
  if path && node.path_changed?
26
20
  node.move_to_path(path)
27
21
  elsif move_by_left_id?
@@ -34,7 +34,8 @@ module SimpleNestedSet
34
34
  def initialize(*args)
35
35
  super(node_class, node_class.arel_table)
36
36
  @node = args.first if args.size == 1
37
- @where_values = self.class.scope(node).instance_variable_get(:@where_values) if node
37
+ @where_values = self.class.scope(args.first).instance_variable_get(:@where_values) if args.size == 1
38
+ # TODO how to set order(:lft) here? it's now being added on various scopes (see class methods), would be better to have it here.
38
39
  end
39
40
 
40
41
  def save!
@@ -1,3 +1,3 @@
1
1
  module SimpleNestedSet
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
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: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 18
10
- version: 0.0.18
9
+ - 19
10
+ version: 0.0.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs