populate-me 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/populate_me/document_mixins/admin_adapter.rb +6 -1
- data/lib/populate_me/mongo.rb +8 -0
- data/lib/populate_me/version.rb +1 -1
- data/test/test_mongo.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2770ba89bcfa96ad56baafdf141c67891317044051f44b117a8e6b438f7c432
|
4
|
+
data.tar.gz: f076278f23d91e5c59c141b39698c34a9083c5861ba01f41a3692d587bc0b73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f952a4160015147d54bab9a504f189613521e33342561e95ae33710cb2c3929a9a9512a96d6b0ed2812571a3faa7c972f3b550556884e44c9c0cd7df19922ed0
|
7
|
+
data.tar.gz: cd10b6ec3d88432f6255803150c6c1b129b0ffab6a6736d92243238976cfbf295413ea5a1cd9251029edfd798cdead3ac98fcbf51cd3f415a0011702ada41c5b
|
@@ -76,11 +76,16 @@ module PopulateMe
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def admin_get id
|
79
|
+
return self.admin_get_multiple(id) if id.is_a?(Array)
|
79
80
|
self.cast do
|
80
|
-
documents.find{|doc| doc[id_string_key]==id }
|
81
|
+
documents.find{|doc| doc[id_string_key] == id }
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
85
|
+
def admin_get_multiple ids, o={sort: nil}
|
86
|
+
self.admin_find(o.merge(query: {id_string_key => {'$in' => ids.uniq.compact}}))
|
87
|
+
end
|
88
|
+
|
84
89
|
def admin_find o={}
|
85
90
|
o[:query] ||= {}
|
86
91
|
docs = self.cast{documents}.find_all do |d|
|
data/lib/populate_me/mongo.rb
CHANGED
@@ -88,11 +88,19 @@ module PopulateMe
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def admin_get theid
|
91
|
+
return self.admin_get_multiple(theid) if theid.is_a?(Array)
|
91
92
|
theid = string_or_object_id theid
|
92
93
|
self.cast{ collection.find({id_string_key => theid}).first }
|
93
94
|
end
|
94
95
|
alias_method :[], :admin_get
|
95
96
|
|
97
|
+
def admin_get_multiple theids, o={sort: nil}
|
98
|
+
theids = theids.uniq.compact.map{|theid| string_or_object_id(theid) }
|
99
|
+
self.admin_find(o.merge({
|
100
|
+
query: {id_string_key => {'$in' => theids} }
|
101
|
+
}))
|
102
|
+
end
|
103
|
+
|
96
104
|
def admin_find o={}
|
97
105
|
query = o.delete(:query) || {}
|
98
106
|
o[:sort] ||= @current_sort
|
data/lib/populate_me/version.rb
CHANGED
data/test/test_mongo.rb
CHANGED
@@ -126,6 +126,19 @@ describe 'PopulateMe::Mongo' do
|
|
126
126
|
assert_equal "regular", LowFish.admin_get(regular_fish_id).name
|
127
127
|
end
|
128
128
|
|
129
|
+
it "Should get multiple items" do
|
130
|
+
# Order is not respected
|
131
|
+
alpha_id = LowFish.new(name: "alpha").perform_create
|
132
|
+
beta_id = LowFish.new(name: "beta").perform_create
|
133
|
+
gamma_id = LowFish.new(name: "gamma").perform_create
|
134
|
+
items = LowFish.admin_get([alpha_id, beta_id, nil, alpha_id])
|
135
|
+
assert items.is_a?(Array)
|
136
|
+
assert_equal 2, items.count
|
137
|
+
refute_nil items.find{|i| i.id == alpha_id}
|
138
|
+
refute_nil items.find{|i| i.id == beta_id}
|
139
|
+
assert_nil items.find{|i| i.id == gamma_id}
|
140
|
+
end
|
141
|
+
|
129
142
|
it 'Should have the [] shortcut for admin_get' do
|
130
143
|
LowFish.collection.insert_one(_id: 42, name: "H2G2")
|
131
144
|
assert_equal LowFish[42], LowFish.admin_get(42)
|
@@ -138,7 +151,7 @@ describe 'PopulateMe::Mongo' do
|
|
138
151
|
LowFish.collection.insert_one(_id: 40, name: "Bran")
|
139
152
|
items = LowFish.admin_find
|
140
153
|
assert items.is_a?(Array)
|
141
|
-
|
154
|
+
assert_equal 4, items.count
|
142
155
|
assert_equal 10, items[0].id
|
143
156
|
items = LowFish.admin_find query: {name: 'Bran'}
|
144
157
|
assert items.is_a?(Array)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: populate-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|