populate-me 0.1.7 → 0.1.8
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/mongo.rb +7 -0
- data/lib/populate_me/version.rb +1 -1
- data/test/test_mongo.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da7af0c111b47e4027615b2db466b6b5564ee1b
|
4
|
+
data.tar.gz: 6323247fa15e8b90a5fc8944273d93405782ff93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8fe0a34b4f19b495b3fa77bcd833ebdbe83ecfaf39f98acd07d3ed23c99aceea4631cd085a60f6da2e95eb0ce76d32ee7254f7aa679622e5b6733705a3cb4f4
|
7
|
+
data.tar.gz: a70e4a4838712eeb3210552c65419e39f242858178ed1dc77a3432655c79d9b13336566753db1f1297520c6f4e6cf1554ed489dfa66c9aad7eb40bc03c476dde
|
data/lib/populate_me/mongo.rb
CHANGED
@@ -66,6 +66,13 @@ module PopulateMe
|
|
66
66
|
def admin_find o={}
|
67
67
|
query = o.delete(:query) || {}
|
68
68
|
o[:sort] ||= @current_sort
|
69
|
+
if o.key?(:fields)
|
70
|
+
o[:projection] = o[:fields].inject({}) do |h, f|
|
71
|
+
h[f.to_sym] = 1
|
72
|
+
h
|
73
|
+
end
|
74
|
+
o.delete(:fields)
|
75
|
+
end
|
69
76
|
self.cast{ collection.find(query, o) }
|
70
77
|
end
|
71
78
|
|
data/lib/populate_me/version.rb
CHANGED
data/test/test_mongo.rb
CHANGED
@@ -77,6 +77,7 @@ describe 'PopulateMe::Mongo' do
|
|
77
77
|
|
78
78
|
class LowFish < PopulateMe::Mongo
|
79
79
|
field :name
|
80
|
+
field :lastname
|
80
81
|
end
|
81
82
|
|
82
83
|
before do
|
@@ -128,6 +129,13 @@ describe 'PopulateMe::Mongo' do
|
|
128
129
|
assert_equal 42, LowFish.admin_find(query: {name: 'H2G2'})[0].id
|
129
130
|
end
|
130
131
|
|
132
|
+
it 'Should admin_find while turning fields option into a projection option' do
|
133
|
+
LowFish.collection.insert_one(_id: 42, name: "John", lastname: "Doe")
|
134
|
+
found = LowFish.admin_find(query: {lastname: "Doe"}, fields: ['_id', 'lastname'])[0]
|
135
|
+
assert_equal 42, found.id
|
136
|
+
assert_nil found.name
|
137
|
+
end
|
138
|
+
|
131
139
|
it 'Should delete' do
|
132
140
|
herbert = LowFish.new(name: "herbert")
|
133
141
|
herbert.perform_create
|
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.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|