fetcheable_on_api 0.1.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5da599e1695d12e998a218d88038c4999f8e063a
4
- data.tar.gz: 97677585e0c3b456f220326dd78ac708492af438
3
+ metadata.gz: 3f28d2fc702708ed0bec47b13b9d4573f0d817c5
4
+ data.tar.gz: 4a33d75b625c595516143e00088a6b5374cb1b85
5
5
  SHA512:
6
- metadata.gz: b4cf30622b1a5a2d8e815e3611ec27091e299540d519233166705b91049986c81ae35dc18e68bfe61068f6693a551b22c3247c4629842f6795891e7a565f0a8b
7
- data.tar.gz: fa4048332338e34a424d1f540d2798d789894ec7ca2fb5f95f81205dec8d174900b19cb769ab845aa402fe81eddc7b136d9fec6f8e9683d3f74f24e66132d6ff
6
+ metadata.gz: 8b64b0d3dbc5cf98d933e4b4187c86ab91ed9e35fe06d13450973a364cb07ffbbffd4ec5d319713de04ffde8041ebcc0f5a7f71079b5df9174e251ca20040662
7
+ data.tar.gz: 73292fdb8271450c7bce3f67e4daa08d26c77e129e249e519e41fb7080831dda22ebaca12d7c3803b22c02799fd6145169091aa49b2a1fc8e25ad549a39fe559
data/README.md CHANGED
@@ -19,6 +19,13 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install fetcheable_on_api
21
21
 
22
+ Finally, run the install generator:
23
+
24
+ $ rails generate fetcheable_on_api:install
25
+
26
+ It will create the following initializer `config/initializers/fetcheable_on_api.rb`.
27
+ This file contains all the informations about the existing configuration options.
28
+
22
29
  ## Usage
23
30
 
24
31
  Imagine the following models called question and answer:
@@ -280,6 +287,28 @@ $ curl -X GET \
280
287
  ]
281
288
  ```
282
289
 
290
+ Multiple filter values can be combined in a comma-separated list.
291
+
292
+ ```bash
293
+ $ curl -X GET \
294
+ 'http://localhost:3000/questions?filter[content]=real,simple'
295
+
296
+ [
297
+ {
298
+ "id": 4,
299
+ "position": 2,
300
+ "content": "Is it so simple?",
301
+ "answer": "Yes"
302
+ },
303
+ {
304
+ "id": 5,
305
+ "position": 3,
306
+ "content": "Is this real life?",
307
+ "answer": "Yes this is real life"
308
+ }
309
+ ]
310
+ ```
311
+
283
312
  You can also define a filter through an association like this:
284
313
 
285
314
  ```ruby
@@ -51,14 +51,16 @@ module FetcheableOnApi
51
51
  .permit(filters_configuration.keys)
52
52
  .to_hash
53
53
 
54
- filtering = filter_params.map do |column, value|
55
- column_name = filters_configuration[column.to_sym].fetch(:as, column)
56
- klass = filters_configuration[column.to_sym].fetch(:class_name, collection.klass)
54
+ filtering = filter_params.map do |column, values|
55
+ values.split(',').map do |value|
56
+ column_name = filters_configuration[column.to_sym].fetch(:as, column)
57
+ klass = filters_configuration[column.to_sym].fetch(:class_name, collection.klass)
57
58
 
58
- klass.arel_table[column_name].matches("%#{value}%")
59
+ klass.arel_table[column_name].matches("%#{value}%")
60
+ end.inject(:or)
59
61
  end
60
62
 
61
- collection.where(filtering.inject(:and))
63
+ collection.where(filtering.flatten.compact.inject(:and))
62
64
  end
63
65
  end
64
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FetcheableOnApi
4
- VERSION = '0.1.2'.freeze
4
+ VERSION = '0.1.3'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcheable_on_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien