jsonapi.rb 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/jsonapi/filtering.rb +12 -7
- data/lib/jsonapi/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: b953a7e7e5eba1a9cb24e6b7e4eb11a3d992b1f9
|
4
|
+
data.tar.gz: d082592d88b8b2e6a87ecc02f83ae5a4b9c8dc82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4ceecb9f9765f5b1f6ba3c765163871b9d5a1e898fb81f6a4ca356ff365230b188cc103da845e6ea5e237be3d17ee413d217d4bca926803c00b564a20eefad0
|
7
|
+
data.tar.gz: c05b90c5b9853652f7111a4d323a6e9489f6df405b121e3219fcd0c8479960c534de8bbe616fdbe59042367b2a8f570095203ef922aa73f080009dc4f8e5d40c
|
data/Gemfile.lock
CHANGED
data/lib/jsonapi/filtering.rb
CHANGED
@@ -9,11 +9,16 @@ module JSONAPI
|
|
9
9
|
# @param requested_field [String] the field to parse
|
10
10
|
# @return [Array] with the fields and the predicate
|
11
11
|
def self.extract_attributes_and_predicate(requested_field)
|
12
|
+
predicates = []
|
12
13
|
field_name = requested_field.to_s.dup
|
13
|
-
predicate = Ransack::Predicate.detect_and_strip_from_string!(field_name)
|
14
|
-
predicate = Ransack::Predicate.named(predicate)
|
15
14
|
|
16
|
-
|
15
|
+
while Ransack::Predicate.detect_from_string(field_name).present? do
|
16
|
+
predicate = Ransack::Predicate
|
17
|
+
.detect_and_strip_from_string!(field_name)
|
18
|
+
predicates << Ransack::Predicate.named(predicate)
|
19
|
+
end
|
20
|
+
|
21
|
+
[field_name.split(/_and_|_or_/), predicates.reverse]
|
17
22
|
end
|
18
23
|
|
19
24
|
private
|
@@ -49,14 +54,14 @@ module JSONAPI
|
|
49
54
|
allowed_fields = allowed_fields.map(&:to_s)
|
50
55
|
|
51
56
|
requested.each_pair do |requested_field, to_filter|
|
52
|
-
field_names,
|
57
|
+
field_names, predicates = JSONAPI::Filtering
|
53
58
|
.extract_attributes_and_predicate(requested_field)
|
54
59
|
|
55
60
|
if to_filter.is_a?(String) && to_filter.include?(',')
|
56
61
|
to_filter = to_filter.split(',')
|
57
62
|
end
|
58
63
|
|
59
|
-
if
|
64
|
+
if predicates.any? && (field_names - allowed_fields).empty?
|
60
65
|
filtered[requested_field] = to_filter
|
61
66
|
end
|
62
67
|
end
|
@@ -81,11 +86,11 @@ module JSONAPI
|
|
81
86
|
dir = 'asc'
|
82
87
|
end
|
83
88
|
|
84
|
-
field_names,
|
89
|
+
field_names, predicates = JSONAPI::Filtering
|
85
90
|
.extract_attributes_and_predicate(requested_field)
|
86
91
|
|
87
92
|
next unless (field_names - allowed_fields).empty?
|
88
|
-
next if !options[:sort_with_expressions] &&
|
93
|
+
next if !options[:sort_with_expressions] && predicates.any?
|
89
94
|
|
90
95
|
# Convert to strings instead of hashes to allow joined table columns.
|
91
96
|
filtered << [requested_field, dir].join(' ')
|
data/lib/jsonapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Suscov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_jsonapi
|