populate-me 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0e27d15a2c44ac669b4eb4ed1beac8c7ca44d00
4
- data.tar.gz: 06ad2e485704568cde6e158d7922da7d5f84317c
3
+ metadata.gz: 0da7af0c111b47e4027615b2db466b6b5564ee1b
4
+ data.tar.gz: 6323247fa15e8b90a5fc8944273d93405782ff93
5
5
  SHA512:
6
- metadata.gz: 8c1ba4179b57768cdbca23002ecfc590360ea0647299fbce20fc143048df19489dfc23c0d0730ec534eac33d6afdcb00f2a1b2fe08a1052acba2536f4c10edc3
7
- data.tar.gz: 8bd55f253b92b6c714b8533ccdd90ea3d1d83eda83b84ee83d718c38bcdcc4497c320d414640af8d445efc165f714d7b216f14d93daa76171338e36543cb8d76
6
+ metadata.gz: f8fe0a34b4f19b495b3fa77bcd833ebdbe83ecfaf39f98acd07d3ed23c99aceea4631cd085a60f6da2e95eb0ce76d32ee7254f7aa679622e5b6733705a3cb4f4
7
+ data.tar.gz: a70e4a4838712eeb3210552c65419e39f242858178ed1dc77a3432655c79d9b13336566753db1f1297520c6f4e6cf1554ed489dfa66c9aad7eb40bc03c476dde
@@ -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
 
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
4
4
 
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.7
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-07-31 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils