query_params 1.3.3 → 1.4.3
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 +4 -4
- data/README.md +2 -2
- data/lib/query_params/condition.rb +12 -6
- data/lib/query_params/filter.rb +4 -0
- data/lib/query_params/version.rb +1 -1
- 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: 322226a09a5fb8822a75fe7edf985d0b43d9dcff
|
|
4
|
+
data.tar.gz: 4e665ac550f94894649871f0ed03f2448108f701
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01c865f8a245237840e5b4ca897815eec27870fa1ab267d5b7a350ee2619dc2a3632d3bd7c43b3b3f04e25d4c4a54db504558b3115c6792ce5a4c2dbbe663f42
|
|
7
|
+
data.tar.gz: 47f2367a3cad7ba976018767c904bd94ac429fa7c007ecc8ee373315a9b3a9d27959df73374ec5b6316b178dc5d8f23d4c64670d36e6b3a3b7eca7463458f825
|
data/README.md
CHANGED
|
@@ -28,8 +28,8 @@ Or install it yourself as:
|
|
|
28
28
|
|
|
29
29
|
```ruby
|
|
30
30
|
# Only query params
|
|
31
|
-
URI::QueryParams.filters(filters: ["type = 1", "height <=
|
|
32
|
-
# => "type::eq(1)|height::le(
|
|
31
|
+
URI::QueryParams.filters(filters: ["type = 1", "height <= 2", "age between 18 and 21"], "status in(1,3,5)")
|
|
32
|
+
# => "type::eq(1)|height::le(2)|age::bt(18,21)|status::in(1,3,5)"
|
|
33
33
|
|
|
34
34
|
# Complete URI
|
|
35
35
|
URI::QueryParams.build_uri(base_uri: "http://domain.com/search", q: "Mark", filters: ["age <= 18"])
|
|
@@ -2,7 +2,7 @@ require "query_params"
|
|
|
2
2
|
|
|
3
3
|
module Condition
|
|
4
4
|
|
|
5
|
-
OPERATORS = { "=" => "eq", ">=" => "ge", "<=" => "le", "between" => "bt" }
|
|
5
|
+
OPERATORS = { "=" => "eq", ">=" => "ge", "<=" => "le", "between" => "bt", "in" => "in" }
|
|
6
6
|
|
|
7
7
|
def set_conditions(conditions)
|
|
8
8
|
|
|
@@ -16,9 +16,12 @@ module Condition
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def set_query(condition)
|
|
19
|
+
|
|
20
|
+
condition = condition.gsub(/ in\(/i, ' in (')
|
|
21
|
+
|
|
19
22
|
tokens = condition.split(" ")
|
|
20
23
|
|
|
21
|
-
raise(ArgumentError, "Invalid condition: #{condition}.
|
|
24
|
+
raise(ArgumentError, "Invalid condition: #{condition}. Probably, the operator was not separated by space.") if tokens.size < 3
|
|
22
25
|
|
|
23
26
|
field = tokens[0].strip
|
|
24
27
|
operator = tokens[1].strip.downcase
|
|
@@ -26,13 +29,16 @@ module Condition
|
|
|
26
29
|
|
|
27
30
|
raise(ArgumentError, "Invalid operator. Accepted tokens: #{OPERATORS.values}") if OPERATORS[operator].nil?
|
|
28
31
|
|
|
29
|
-
if operator
|
|
30
|
-
# queryParam.eq('age', 18)
|
|
31
|
-
self.send(OPERATORS[operator], field, value)
|
|
32
|
-
else
|
|
32
|
+
if operator == "between"
|
|
33
33
|
bt_values = value.downcase.split(' and ')
|
|
34
34
|
# queryParam.bt('age', 18, 21)
|
|
35
35
|
self.send(OPERATORS[operator], field, bt_values[0], bt_values[1])
|
|
36
|
+
elsif operator == "in"
|
|
37
|
+
# queryParam.in('age', [1,2,3])
|
|
38
|
+
self.send(OPERATORS[operator], field, value.strip[1..-2].split(","))
|
|
39
|
+
else
|
|
40
|
+
# queryParam.eq('age', 18)
|
|
41
|
+
self.send(OPERATORS[operator], field, value)
|
|
36
42
|
end
|
|
37
43
|
end
|
|
38
44
|
|
data/lib/query_params/filter.rb
CHANGED
data/lib/query_params/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: query_params
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- William Souza
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-07-
|
|
11
|
+
date: 2015-07-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|