fetcheable_on_api 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/fetcheable_on_api/filterable.rb +14 -6
- data/lib/fetcheable_on_api/version.rb +1 -1
- 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: 31b1c8010f858d46838f712d7541ad59894e282025987cd3584e36348b3dbe85
|
4
|
+
data.tar.gz: 38419bb0d86fe2d74071d9efa33352bb813521b5198978ab67815d428dd9e095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83879060c20a6f976d0cee7ce5803261c0e7e207ff95300d607dd190caf07f6237ec5d16980c376caa919d348e6322be3ad0f535175fb6367f2e4dad485f92e0
|
7
|
+
data.tar.gz: aed42afd78ebf7875302ecc833cc3deb8a30381e323200684b9c02dc69f6f9a78136c4eacfb0b86a0ae695645efdd895e32a6802eb3fa37b79e79cf62d604cb6
|
data/README.md
CHANGED
@@ -505,6 +505,10 @@ $ curl -X GET \
|
|
505
505
|
]
|
506
506
|
```
|
507
507
|
|
508
|
+
By default fetcheable_on_api will join the associated model using the
|
509
|
+
`class_name` option you have provided. If another association should be used as
|
510
|
+
the target, use the `association:` option instead.
|
511
|
+
|
508
512
|
Furthermore you can specify one of the supported `Arel` predicate.
|
509
513
|
|
510
514
|
```ruby
|
@@ -53,7 +53,9 @@ module FetcheableOnApi
|
|
53
53
|
def filter_by(*attrs)
|
54
54
|
options = attrs.extract_options!
|
55
55
|
options.symbolize_keys!
|
56
|
-
options.assert_valid_keys(
|
56
|
+
options.assert_valid_keys(
|
57
|
+
:as, :class_name, :with, :format, :association
|
58
|
+
)
|
57
59
|
|
58
60
|
self.filters_configuration = filters_configuration.dup
|
59
61
|
|
@@ -106,14 +108,20 @@ module FetcheableOnApi
|
|
106
108
|
.to_hash
|
107
109
|
|
108
110
|
filtering = filter_params.map do |column, values|
|
109
|
-
|
110
|
-
|
111
|
-
|
111
|
+
config = filters_configuration[column.to_sym]
|
112
|
+
|
113
|
+
format = config.fetch(:format, :string)
|
114
|
+
column_name = config.fetch(:as, column)
|
115
|
+
klass = config.fetch(:class_name, collection.klass)
|
112
116
|
collection_klass = collection.name.constantize
|
113
|
-
|
117
|
+
association_class_or_name = config.fetch(
|
118
|
+
:association, klass.table_name.to_sym
|
119
|
+
)
|
120
|
+
|
121
|
+
predicate = config.fetch(:with, :ilike)
|
114
122
|
|
115
123
|
if collection_klass != klass
|
116
|
-
collection = collection.joins(
|
124
|
+
collection = collection.joins(association_class_or_name)
|
117
125
|
end
|
118
126
|
|
119
127
|
if %i[between not_between].include?(predicate)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fetcheable_on_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|