populate-me 0.18.1 → 0.20.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 +11 -1
- data/lib/populate_me/document_mixins/schema.rb +10 -2
- data/lib/populate_me/version.rb +1 -1
- data/populate-me.gemspec +3 -3
- data/test/test_document_schema.rb +22 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3359034df211dd6eef9b9142fd38b7a96db59d0f82bf05efc29ee594dcac332
|
4
|
+
data.tar.gz: e13861e7a4ea3b42e6587bf0ea492cd5ec8c0f2f3c38f8617169ad3864768152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08f7a97b54471d59a00f856a33190a44eecc9c0ea6e7191cc9177a52b92858d43f287b7839fcc481be04253ed1d8ccf409e14045f74892968af2cd0fe726b856'
|
7
|
+
data.tar.gz: 6cbb05d6aed20c6f8cd277c5944d85c8521fc6fc6371a8f338fb0cad6b180cc8b28365e59fb75a4993d48afafbb89cc079b30a7c160e376dc3fbf347e0a6a511
|
@@ -92,7 +92,17 @@ module PopulateMe
|
|
92
92
|
|
93
93
|
def admin_find o={}
|
94
94
|
o[:query] ||= {}
|
95
|
-
docs = self.cast
|
95
|
+
docs = self.cast do
|
96
|
+
if o.key?( :fields )
|
97
|
+
documents.map do |h|
|
98
|
+
h.select do |k,v|
|
99
|
+
o[:fields].map(&:to_s).include?( k )
|
100
|
+
end
|
101
|
+
end
|
102
|
+
else
|
103
|
+
documents
|
104
|
+
end
|
105
|
+
end.find_all do |d|
|
96
106
|
o[:query].inject(true) do |out,(k,v)|
|
97
107
|
out && (d.__send__(k)==v)
|
98
108
|
end
|
@@ -165,11 +165,19 @@ module PopulateMe
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
+
def default_select_fields
|
169
|
+
[
|
170
|
+
self.id_string_key,
|
171
|
+
self.label_field,
|
172
|
+
self.admin_image_field,
|
173
|
+
].compact.uniq
|
174
|
+
end
|
175
|
+
|
168
176
|
def to_select_options o={}
|
169
177
|
proc do
|
170
178
|
items = self.admin_find({
|
171
|
-
query: (o[:query]||{}),
|
172
|
-
fields: [
|
179
|
+
query: ( o[:query] || {} ),
|
180
|
+
fields: ( o[:fields] || default_select_fields ),
|
173
181
|
})
|
174
182
|
output = items.sort_by do |i|
|
175
183
|
i.to_s.downcase
|
data/lib/populate_me/version.rb
CHANGED
data/populate-me.gemspec
CHANGED
@@ -18,14 +18,14 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
|
20
20
|
s.add_dependency 'web-utils', '~> 0'
|
21
|
-
s.add_dependency 'sinatra', '~>
|
21
|
+
s.add_dependency 'sinatra', '~> 3'
|
22
22
|
s.add_dependency 'json', '~> 2.1'
|
23
23
|
|
24
24
|
s.add_development_dependency 'bundler', '>= 2.2.10'
|
25
25
|
s.add_development_dependency 'minitest', '~> 5.8'
|
26
|
-
s.add_development_dependency 'rack-test', '~>
|
26
|
+
s.add_development_dependency 'rack-test', '~> 2'
|
27
27
|
s.add_development_dependency 'rack-cerberus', '~> 1.0'
|
28
|
-
s.add_development_dependency 'mongo', '~> 2.
|
28
|
+
s.add_development_dependency 'mongo', '~> 2.18'
|
29
29
|
s.add_development_dependency 'rack-grid-serve', '~> 0.0.8'
|
30
30
|
s.add_development_dependency 'aws-sdk-s3', '~> 1'
|
31
31
|
s.add_development_dependency 'racksh', '~> 1.0'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'web_utils'
|
2
3
|
require 'populate_me/document'
|
3
4
|
require 'populate_me/attachment'
|
4
5
|
|
@@ -114,6 +115,14 @@ describe PopulateMe::Document, 'Schema' do
|
|
114
115
|
]
|
115
116
|
end
|
116
117
|
|
118
|
+
class SelectWithMoreFields < PopulateMe::Document
|
119
|
+
field :name
|
120
|
+
field :parent_name
|
121
|
+
def to_s
|
122
|
+
WebUtils.blank?(self.parent_name) ? self.name : "#{ self.parent_name } / #{ self.name }"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
117
126
|
before do
|
118
127
|
Selectoptionable.documents = []
|
119
128
|
Selectoptionable.new(id: '1', name: 'Joe', slug: 'joe').save
|
@@ -122,10 +131,14 @@ describe PopulateMe::Document, 'Schema' do
|
|
122
131
|
Selectoptionable.new(id: '4', name: 'Averell', slug: 'averell').save
|
123
132
|
Selectpreviewable.documents = []
|
124
133
|
Selectpreviewable.new(id: '1', name: 'Project', img: 'project.jpg').save
|
134
|
+
SelectWithMoreFields.documents = []
|
135
|
+
SelectWithMoreFields.new(id: '1', name: 'Product', parent_name: 'Collection').save
|
125
136
|
end
|
126
137
|
|
127
138
|
after do
|
128
139
|
Selectoptionable.documents = []
|
140
|
+
Selectpreviewable.documents = []
|
141
|
+
SelectWithMoreFields.documents = []
|
129
142
|
end
|
130
143
|
|
131
144
|
it 'Formats all items for a select_options' do
|
@@ -156,6 +169,15 @@ describe PopulateMe::Document, 'Schema' do
|
|
156
169
|
assert_equal '/attachment/selectpreviewable/project.populate_me_thumb.jpg', output[0][:preview_uri]
|
157
170
|
end
|
158
171
|
|
172
|
+
it 'Adds fields to query if option is passed' do
|
173
|
+
output = SelectWithMoreFields.to_select_options.call
|
174
|
+
assert_equal 'Product', output[0][:description]
|
175
|
+
output = SelectWithMoreFields.to_select_options({
|
176
|
+
fields: SelectWithMoreFields.default_select_fields + [:parent_name],
|
177
|
+
}).call
|
178
|
+
assert_equal 'Collection / Product', output[0][:description]
|
179
|
+
end
|
180
|
+
|
159
181
|
end
|
160
182
|
|
161
183
|
describe 'Polymorphism' 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.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rack-cerberus
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '2.
|
117
|
+
version: '2.18'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '2.
|
124
|
+
version: '2.18'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rack-grid-serve
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -259,7 +259,7 @@ homepage: https://github.com/mig-hub/populate-me
|
|
259
259
|
licenses:
|
260
260
|
- MIT
|
261
261
|
metadata: {}
|
262
|
-
post_install_message:
|
262
|
+
post_install_message:
|
263
263
|
rdoc_options: []
|
264
264
|
require_paths:
|
265
265
|
- lib
|
@@ -274,8 +274,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
274
|
- !ruby/object:Gem::Version
|
275
275
|
version: '0'
|
276
276
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
278
|
-
signing_key:
|
277
|
+
rubygems_version: 3.3.7
|
278
|
+
signing_key:
|
279
279
|
specification_version: 4
|
280
280
|
summary: PopulateMe is an admin system for web applications.
|
281
281
|
test_files:
|