populate-me 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/populate_me/mongo/mutation.rb +14 -8
- data/populate-me.gemspec +1 -1
- metadata +2 -2
@@ -24,13 +24,16 @@ module PopulateMe
|
|
24
24
|
def human_name; self.name.gsub(/([A-Z])/, ' \1')[1..-1]; end
|
25
25
|
def human_plural_name; human_name+'s'; end
|
26
26
|
def collection; db[self.name]; end
|
27
|
-
def
|
27
|
+
def correct_id_class(id)
|
28
28
|
if id.is_a?(String)&&BSON::ObjectId.legal?(id)
|
29
|
-
|
29
|
+
return BSON::ObjectId.from_string(id)
|
30
30
|
elsif !id.is_a?(BSON::ObjectId)
|
31
|
-
|
31
|
+
return ''
|
32
32
|
end
|
33
|
-
|
33
|
+
id
|
34
|
+
end
|
35
|
+
def ref(id)
|
36
|
+
{'_id' => (id.kind_of?(Array) ? {'$in'=> id.map{|i|correct_id_class(i)} } : correct_id_class(id)) }
|
34
37
|
end
|
35
38
|
def find(selector={},opts={})
|
36
39
|
selector.update(opts.delete(:selector)||{})
|
@@ -65,6 +68,12 @@ module PopulateMe
|
|
65
68
|
def get(id, opts={}); doc = collection.find_one(ref(id), opts); doc.nil? ? nil : self.new(doc); end
|
66
69
|
def delete(id); collection.remove(ref(id)); end
|
67
70
|
|
71
|
+
def get_multiple(ids, opts={})
|
72
|
+
ids.map!{|id|correct_id_class(id)}
|
73
|
+
sort_proc = proc{ |a,b| ids.index(a['_id'])<=>ids.index(b['_id']) }
|
74
|
+
self.find(ref(ids), opts).to_a.sort(&sort_proc)
|
75
|
+
end
|
76
|
+
|
68
77
|
def is_unique(doc={})
|
69
78
|
return unless collection.count==0
|
70
79
|
self.new(doc).save
|
@@ -133,10 +142,7 @@ module PopulateMe
|
|
133
142
|
klass = resolve_class(k)
|
134
143
|
key = klass.foreign_key_name(true)
|
135
144
|
end
|
136
|
-
|
137
|
-
selector = {'_id'=>{'$in'=>ids}}
|
138
|
-
sort_proc = proc{ |a,b| ids.index(a['_id'])<=>ids.index(b['_id']) }
|
139
|
-
klass.find(selector, opts).to_a.sort(&sort_proc)
|
145
|
+
klass.get_multiple((@doc[key]||[]), opts)
|
140
146
|
end
|
141
147
|
def first_slot_child(k, opts={})
|
142
148
|
if k.kind_of?(String)
|
data/populate-me.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'populate-me'
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.19"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "ALPHA !!! Populate Me is relatively complete but simple CMS"
|
6
6
|
s.description = "ALPHA !!! Populate Me is relatively complete but simple CMS. It includes a Rack middleware for putting in your Rack stack, and a bespoke MongoDB ODM. But Populate Me is not really finished yet."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: populate-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack-golem
|