populate-me 0.22.1 → 0.24.0

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
  SHA256:
3
- metadata.gz: 6e61285e7d53d8b5337b323559d62baf02008d11cfed7bff21f1780544de26c8
4
- data.tar.gz: adb51ab13e6840852167c8615eec94d9b021ec6461b9130a73ade99159e0e36e
3
+ metadata.gz: 755c27b5a876d2405fa770ff952f67ed52627cb5c9eb43eb08bb8e2e1fc893e8
4
+ data.tar.gz: ac8e9c0c6f635025b7df65147f2eff229a965317318db44e603f8dd84c73351d
5
5
  SHA512:
6
- metadata.gz: c188a9f59df60376f70e3e262f0c4d5856b2212dea2f483bccc1c611cf013a14dae4b2bc0ea1aee927379ebf9f6e5acca31a8733e8852dff3ff81c6a381163a1
7
- data.tar.gz: f7cf11e6d35e009422e6c61afc1e312b36988b25c089c8fc7262a0f3528391eb5ecbf1101c439c96985877d6fca82b68e03807f6e8bcad06c27bf8324f622479
6
+ metadata.gz: 94dd1bc25eb28bfba53c5f377e8b31085a26ecc827664c9f8852ec91e96337548bc2469a02809cfd098c86c0c50164d4cc054c9233816884aa06c1f2468693ff
7
+ data.tar.gz: 621b36da76ed9bc8d12312c981ea16be38baff25a3ad6875842a313132cd5cd2c37208748e871e92efe1c23e28f31903dc4b259539b67184df43badcca43cfaf
@@ -85,9 +85,16 @@ module PopulateMe
85
85
  documents.find{|doc| doc[id_string_key] == id }
86
86
  end
87
87
  end
88
+ alias_method :[], :admin_get
88
89
 
89
90
  def admin_get_multiple ids, o={sort: nil}
90
- self.admin_find(o.merge(query: {id_string_key => {'$in' => ids.uniq.compact}}))
91
+ clean_ids = ids.uniq.compact
92
+ items = self.cast do
93
+ documents.select{|doc| clean_ids.include?(doc[id_string_key]) }
94
+ end
95
+ clean_ids.map do |id|
96
+ items.find{|item| item.id == id}
97
+ end.compact
91
98
  end
92
99
 
93
100
  def admin_find o={}
@@ -6,7 +6,7 @@ module PopulateMe
6
6
  class MissingMongoDBError < StandardError; end
7
7
 
8
8
  class Mongo < Document
9
-
9
+
10
10
  self.settings.instance_eval do
11
11
  def collection_name
12
12
  puts 'yo'
@@ -95,10 +95,13 @@ module PopulateMe
95
95
  alias_method :[], :admin_get
96
96
 
97
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} }
98
+ clean_ids = theids.uniq.compact.map{|theid| string_or_object_id(theid) }
99
+ items = self.admin_find(o.merge({
100
+ query: {id_string_key => {'$in' => clean_ids} }
101
101
  }))
102
+ clean_ids.map do |id|
103
+ items.find{|item| item.id == id}
104
+ end.compact
102
105
  end
103
106
 
104
107
  def admin_find o={}
@@ -21,7 +21,7 @@ module PopulateMe
21
21
  defaults << "-strip " if o[:strip]
22
22
  defaults << "-interlace Plane " if o[:progressive] and [:jpg,:jpeg].include?(ext.to_sym)
23
23
  job = lambda{ |src,dst|
24
- Kernel.system "convert \"#{src}\" #{defaults}#{convert_string} \"#{dst}\""
24
+ Kernel.system "magick \"#{src}\" #{defaults}#{convert_string} \"#{dst}\""
25
25
  }
26
26
  self.new name, ext, job
27
27
  end
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.22.1'
2
+ VERSION = '0.24.0'
3
3
  end
4
4
 
@@ -97,12 +97,12 @@ describe PopulateMe::Document, 'AdminAdapter' do
97
97
  end
98
98
 
99
99
  describe '::admin_find ::admin_find_first' do
100
-
100
+
101
101
  class FindablePerson < PopulateMe::Document
102
102
  field :first_name
103
103
  field :last_name
104
104
  end
105
-
105
+
106
106
  before do
107
107
  FindablePerson.documents = []
108
108
  FindablePerson.new(first_name: 'Bobby', last_name: 'Peru').save
@@ -136,6 +136,46 @@ describe PopulateMe::Document, 'AdminAdapter' do
136
136
 
137
137
  end
138
138
 
139
+ describe '::admin_get' do
140
+
141
+ class GetablePerson < PopulateMe::Document
142
+ field :name
143
+ field :lastname
144
+ end
145
+
146
+ before do
147
+ GetablePerson.documents = []
148
+ end
149
+
150
+ it "Should get correct item" do
151
+ jackson_id = GetablePerson.new(name: "jackson").save
152
+ assert_equal "jackson", GetablePerson.admin_get(jackson_id).name
153
+ assert_equal "jackson", GetablePerson.admin_get(jackson_id.to_s).name
154
+ assert_nil GetablePerson.admin_get("nonexistentid")
155
+
156
+ regular_id = GetablePerson.new(id: 87, name: "regular").save
157
+ # need to test with .to_s
158
+ assert_equal "regular", GetablePerson.admin_get(regular_id).name
159
+ end
160
+
161
+ it "Should get multiple items" do
162
+ # Order is not respected
163
+ alpha_id = GetablePerson.new(name: "alpha").save
164
+ beta_id = GetablePerson.new(name: "beta").save
165
+ gamma_id = GetablePerson.new(name: "gamma").save
166
+ items = GetablePerson.admin_get([beta_id, "nonexistentid", alpha_id, beta_id, nil, alpha_id])
167
+ assert items.is_a?(Array)
168
+ assert_equal 2, items.count
169
+ refute_nil items.find{|i| i.id == alpha_id}
170
+ refute_nil items.find{|i| i.id == beta_id}
171
+ assert_nil items.find{|i| i.id == gamma_id}
172
+ # respects natural order of uniq compact elements
173
+ assert_equal beta_id, items[0].id
174
+ assert_equal alpha_id, items[1].id
175
+ end
176
+
177
+ end
178
+
139
179
  describe '::admin_distinct' do
140
180
 
141
181
  class Distinction < PopulateMe::Document
data/test/test_mongo.rb CHANGED
@@ -131,12 +131,15 @@ describe 'PopulateMe::Mongo' do
131
131
  alpha_id = LowFish.new(name: "alpha").perform_create
132
132
  beta_id = LowFish.new(name: "beta").perform_create
133
133
  gamma_id = LowFish.new(name: "gamma").perform_create
134
- items = LowFish.admin_get([alpha_id, beta_id, nil, alpha_id])
134
+ items = LowFish.admin_get([beta_id, "nonexistentid", alpha_id, beta_id, nil, alpha_id])
135
135
  assert items.is_a?(Array)
136
136
  assert_equal 2, items.count
137
137
  refute_nil items.find{|i| i.id == alpha_id}
138
138
  refute_nil items.find{|i| i.id == beta_id}
139
139
  assert_nil items.find{|i| i.id == gamma_id}
140
+ # respects natural order of uniq compact elements
141
+ assert_equal beta_id, items[0].id
142
+ assert_equal alpha_id, items[1].id
140
143
  end
141
144
 
142
145
  it 'Should have the [] shortcut for admin_get' do
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.22.1
4
+ version: 0.24.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: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2025-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils