noodall-core 0.3.1 → 0.3.2
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/VERSION +1 -1
- data/lib/noodall/node.rb +12 -12
- data/noodall-core.gemspec +1 -1
- data/spec/node_spec.rb +5 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/noodall/node.rb
CHANGED
@@ -76,29 +76,29 @@ module Noodall
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def last?
|
79
|
-
position ==
|
79
|
+
position == search_class.count(:_id => {"$ne" => self._id}, parent_id_field => self[parent_id_field])
|
80
80
|
end
|
81
81
|
def move_lower
|
82
|
-
sibling =
|
82
|
+
sibling = search_class.first(:position => {"$gt" => self.position}, parent_id_field => self[parent_id_field], :order => 'position ASC')
|
83
83
|
|
84
84
|
tmp = sibling.position
|
85
85
|
sibling.position = self.position
|
86
86
|
self.position = tmp
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
search_class.collection.update({:_id => self._id}, self.to_mongo)
|
89
|
+
search_class.collection.update({:_id => sibling._id}, sibling.to_mongo)
|
90
90
|
|
91
91
|
global_updated!
|
92
92
|
end
|
93
93
|
def move_higher
|
94
|
-
sibling =
|
94
|
+
sibling = search_class.first(:position => {"$lt" => self.position}, parent_id_field => self[parent_id_field], :order => 'position DESC')
|
95
95
|
|
96
96
|
tmp = sibling.position
|
97
97
|
sibling.position = self.position
|
98
98
|
self.position = tmp
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
search_class.collection.update({:_id => self._id}, self.to_mongo)
|
101
|
+
search_class.collection.update({:_id => sibling._id}, sibling.to_mongo)
|
102
102
|
|
103
103
|
global_updated!
|
104
104
|
end
|
@@ -149,16 +149,16 @@ module Noodall
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def siblings
|
152
|
-
|
152
|
+
search_class.where(:_id => {:$ne => self._id}, parent_id_field => self[parent_id_field]).order(tree_order)
|
153
153
|
end
|
154
154
|
|
155
155
|
def self_and_siblings
|
156
|
-
|
156
|
+
search_class.where(parent_id_field => self[parent_id_field]).order(tree_order)
|
157
157
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def children
|
161
|
-
|
161
|
+
search_class.where(parent_id_field => self._id).order(tree_order)
|
162
162
|
end
|
163
163
|
|
164
164
|
private
|
@@ -225,11 +225,11 @@ module Noodall
|
|
225
225
|
after_save :order_siblings
|
226
226
|
def order_siblings
|
227
227
|
if position_changed?
|
228
|
-
|
228
|
+
search_class.collection.update({:_id => {"$ne" => self._id}, :position => {"$gte" => self.position}, parent_id_field => self[parent_id_field]}, { "$inc" => { :position => 1 }}, { :multi => true })
|
229
229
|
self_and_siblings.each_with_index do |sibling, index|
|
230
230
|
unless sibling.position == index
|
231
231
|
sibling.position = index
|
232
|
-
|
232
|
+
search_class.collection.save(sibling.to_mongo, :safe => true)
|
233
233
|
end
|
234
234
|
end
|
235
235
|
end
|
data/noodall-core.gemspec
CHANGED
data/spec/node_spec.rb
CHANGED
@@ -60,7 +60,11 @@ describe Noodall::Node do
|
|
60
60
|
|
61
61
|
describe "within a tree" do
|
62
62
|
before(:each) do
|
63
|
-
|
63
|
+
class LandingPage < Noodall::Node
|
64
|
+
root_template!
|
65
|
+
end
|
66
|
+
|
67
|
+
@root = LandingPage.create!(:title => "Root")
|
64
68
|
|
65
69
|
@child = Page.create!(:title => "Ickle Kid", :parent => @root)
|
66
70
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noodall-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve England
|