mongoid_order 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.
- data/README.rdoc +1 -1
- data/lib/mongoid_order.rb +7 -7
- data/mongoid_order.gemspec +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -16,7 +16,7 @@ To install mongoid_order, simply add it to your Gemfile:
|
|
16
16
|
|
17
17
|
gem 'mongoid_order'
|
18
18
|
|
19
|
-
In order to get the latest development version of
|
19
|
+
In order to get the latest development version of mongoid_order:
|
20
20
|
|
21
21
|
gem 'mongoid_order', :git => 'https://github.com/arkxu/mongoid_order.git'
|
22
22
|
|
data/lib/mongoid_order.rb
CHANGED
@@ -32,26 +32,26 @@ module Mongoid
|
|
32
32
|
# Returns siblings below the current document.
|
33
33
|
# Siblings with a position greater than this documents's position.
|
34
34
|
def lower_siblings
|
35
|
-
self.class.
|
35
|
+
self.class.where(:position.gt => self.position)
|
36
36
|
end
|
37
37
|
|
38
38
|
##
|
39
39
|
# Returns siblings above the current document.
|
40
40
|
# Siblings with a position lower than this documents's position.
|
41
41
|
def higher_siblings
|
42
|
-
self.class.
|
42
|
+
self.class.where(:position.lt => self.position)
|
43
43
|
end
|
44
44
|
|
45
45
|
##
|
46
46
|
# Returns the lowest sibling (could be self)
|
47
47
|
def last_sibling_in_list
|
48
|
-
self.class.
|
48
|
+
self.class.asc(:position).last
|
49
49
|
end
|
50
50
|
|
51
51
|
##
|
52
52
|
# Returns the highest sibling (could be self)
|
53
53
|
def first_sibling_in_list
|
54
|
-
self.class.
|
54
|
+
self.class.asc(:position).first
|
55
55
|
end
|
56
56
|
|
57
57
|
##
|
@@ -84,7 +84,7 @@ module Mongoid
|
|
84
84
|
# Move this node one position up
|
85
85
|
def move_up
|
86
86
|
return if at_top?
|
87
|
-
self.class.
|
87
|
+
self.class.where(:position => self.position - 1).first.inc(:position, 1)
|
88
88
|
inc(:position, -1)
|
89
89
|
end
|
90
90
|
|
@@ -92,7 +92,7 @@ module Mongoid
|
|
92
92
|
# Move this node one position down
|
93
93
|
def move_down
|
94
94
|
return if at_bottom?
|
95
|
-
self.class.
|
95
|
+
self.class.where(:position => self.position + 1).first.inc(:position, -1)
|
96
96
|
inc(:position, 1)
|
97
97
|
end
|
98
98
|
|
@@ -146,7 +146,7 @@ module Mongoid
|
|
146
146
|
if self.class.all.empty? || self.class.all.collect(&:position).compact.empty?
|
147
147
|
self.position = 0
|
148
148
|
else
|
149
|
-
self.position = self.class.
|
149
|
+
self.position = self.class.max(:position) + 1
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
data/mongoid_order.gemspec
CHANGED
metadata
CHANGED