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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ec031ad563f89982fddaaf7afc0c52e0416a6d0
4
- data.tar.gz: 8a4bb4623d4f6296653e03ff3f5a2071040a4bc8
3
+ metadata.gz: b953a7e7e5eba1a9cb24e6b7e4eb11a3d992b1f9
4
+ data.tar.gz: d082592d88b8b2e6a87ecc02f83ae5a4b9c8dc82
5
5
  SHA512:
6
- metadata.gz: 196edb74a5cc741e98d60dd0a0c1ad7c68bf785d604212c9bd1e9a59e544245ff75bd9f2d2fd800263f1ebc764f54a9ff5020bc722d0f06bc1cad39477101f21
7
- data.tar.gz: 0f7407d78935639d366ba3473d86833984e742020f252574ff074817de35f2595828c5837b5bc42af4ed282a94bb2ae4b69a6b2888fc5cb92a24bd0babd56239
6
+ metadata.gz: b4ceecb9f9765f5b1f6ba3c765163871b9d5a1e898fb81f6a4ca356ff365230b188cc103da845e6ea5e237be3d17ee413d217d4bca926803c00b564a20eefad0
7
+ data.tar.gz: c05b90c5b9853652f7111a4d323a6e9489f6df405b121e3219fcd0c8479960c534de8bbe616fdbe59042367b2a8f570095203ef922aa73f080009dc4f8e5d40c
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- jsonapi.rb (1.3.1)
11
+ jsonapi.rb (1.3.2)
12
12
  fast_jsonapi (~> 1.5)
13
13
  rack
14
14
  ransack
@@ -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
- [field_name.split(/_and_|_or_/), predicate]
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, predicate = JSONAPI::Filtering
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 predicate && (field_names - allowed_fields).empty?
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, predicate = JSONAPI::Filtering
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] && predicate
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(' ')
@@ -1,3 +1,3 @@
1
1
  module JSONAPI
2
- VERSION = '1.3.1'
2
+ VERSION = '1.3.2'
3
3
  end
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.1
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-24 00:00:00.000000000 Z
11
+ date: 2019-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_jsonapi