procore-sift 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -0
- data/lib/sift/value_parser.rb +3 -1
- data/lib/sift/version.rb +1 -1
- data/lib/sift/where_handler.rb +10 -6
- 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: 96191da518ce07229dd35fe0375a2b52a4da4ee69b7f506835a236c7e87c77a1
|
4
|
+
data.tar.gz: 994eff7f0ed3417b0a9272e554d4ece07b73fdf99769b89497bbf56cf4259c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6633d0d1260108f39ea161f001980c66102f908ca1b310aab9eefeec9b41dae02bd678dafad461e5f6c4d841b4ac61446f79136b27dd3e159c1b67bb84c5967
|
7
|
+
data.tar.gz: 0d5ce661231cd9caaf98c145be89765e269755619838b60f9ba088d8f4456110794b154e6871887c05d42661dba2e7733e3178449ef474a0be78830a3ae14832
|
data/README.md
CHANGED
@@ -152,6 +152,17 @@ Will return records with next values stored in the JSONB column `metadata`:
|
|
152
152
|
{ data_2: [1,2,3] }
|
153
153
|
```
|
154
154
|
|
155
|
+
When the `null` value is included in the array, it will return also all the records without any value in that property, for example:
|
156
|
+
|
157
|
+
* `?filters[metadata]={"data_2":"[false,null]"}`
|
158
|
+
|
159
|
+
Will return records with next values stored in the JSONB column `metadata`:
|
160
|
+
```ruby
|
161
|
+
{ data_2: null }
|
162
|
+
{ data_2: false }
|
163
|
+
{ data_2: [false] }
|
164
|
+
{ data_1: {another: 'information'} } # When the JSONB key "data_2" is not set.
|
165
|
+
```
|
155
166
|
|
156
167
|
### Filter on JSON Array
|
157
168
|
`int` type filters support sending the values as an array in the URL Query parameters. For example `?filters[id]=[1,2]`. This is a way to keep payloads smaller for GET requests. When URI encoded this will become `filters%5Bid%5D=%5B1,2%5D` which is much smaller the standard format of `filters%5Bid%5D%5B%5D=1&&filters%5Bid%5D%5B%5D=2`.
|
@@ -271,6 +282,28 @@ Running tests:
|
|
271
282
|
$ bundle exec rake test
|
272
283
|
```
|
273
284
|
|
285
|
+
## Publishing
|
286
|
+
|
287
|
+
Publishing is done use the `gem` commandline tool. You must have permissions to publish a new version. Users with permissions can be seen here https://rubygems.org/gems/procore-sift.
|
288
|
+
|
289
|
+
When a bump is desired, the gemspec should have the version number bumped and merged into master.
|
290
|
+
|
291
|
+
Step 1: build the new version
|
292
|
+
`gem build sift.gemspec`
|
293
|
+
```
|
294
|
+
Successfully built RubyGem
|
295
|
+
Name: procore-sift
|
296
|
+
Version: 0.14.0
|
297
|
+
File: procore-sift-0.14.0.gem
|
298
|
+
```
|
299
|
+
|
300
|
+
Step2: Push the updated build
|
301
|
+
`gem push procore-sift-0.14.0.gem`
|
302
|
+
```
|
303
|
+
Pushing gem to https://rubygems.org...
|
304
|
+
Successfully registered gem: procore-sift (0.14.0)
|
305
|
+
```
|
306
|
+
|
274
307
|
## License
|
275
308
|
|
276
309
|
The gem is available as open source under the terms of the [MIT
|
data/lib/sift/value_parser.rb
CHANGED
@@ -33,7 +33,9 @@ module Sift
|
|
33
33
|
return parsed_jsonb if parsed_jsonb.is_a?(Array) || parsed_jsonb.is_a?(String)
|
34
34
|
|
35
35
|
parsed_jsonb.each_with_object({}) do |key_value, hash|
|
36
|
-
|
36
|
+
key = key_value.first
|
37
|
+
value = key_value.last
|
38
|
+
hash[key] = value.is_a?(String) ? parse_json(value) : value
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
data/lib/sift/version.rb
CHANGED
data/lib/sift/where_handler.rb
CHANGED
@@ -18,13 +18,17 @@ module Sift
|
|
18
18
|
return collection.where("#{@param.internal_name} @> ?", val.to_s) if value.is_a?(Array)
|
19
19
|
|
20
20
|
value.each do |key, val|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
collection = if val.is_a?(Array)
|
22
|
+
elements = Hash[val.each_with_index.map { |item, i| ["value_#{i}".to_sym, item.to_s] } ]
|
23
|
+
elements[:all_values] = val.compact.map(&:to_s)
|
24
|
+
main_condition = "('{' || TRANSLATE(#{@param.internal_name}->>'#{key}', '[]','') || '}')::text[] && ARRAY[:all_values]"
|
25
|
+
sub_conditions = val.each_with_index.map do |element, i|
|
26
|
+
"#{@param.internal_name}->>'#{key}' #{element === nil ? 'IS NULL' : "= :value_#{i}"}"
|
27
|
+
end.join(' OR ')
|
28
|
+
collection.where("(#{main_condition}) OR (#{sub_conditions})", elements)
|
29
|
+
else
|
30
|
+
collection.where("#{@param.internal_name}->>'#{key}' = ?", val.to_s)
|
26
31
|
end
|
27
|
-
collection = collection.where(condition, val)
|
28
32
|
end
|
29
33
|
collection
|
30
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procore-sift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Procore Technologies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|