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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d71da3322d2da67e94a8d5753ff04f081ac4e76c05d8afa198f1ebb8b1c2267c
4
- data.tar.gz: 0034ae8441754659242bc72fd900384a3517402baf9ce31de8d01ff348104218
3
+ metadata.gz: 31b1c8010f858d46838f712d7541ad59894e282025987cd3584e36348b3dbe85
4
+ data.tar.gz: 38419bb0d86fe2d74071d9efa33352bb813521b5198978ab67815d428dd9e095
5
5
  SHA512:
6
- metadata.gz: 28db2fe13b6a53cd50ed91bf7ac4c4ba73947676528299c95985cabfadecb174f884d61f15b8832779d65201ce2880149cbff0b7ae2ea8c06acad9f4930f5050
7
- data.tar.gz: ff5e7e8aa569c28e194eaed67f6baeba238e7aa06c69df01983003fa07bd94fd1082ef58d72b7584f5f49ea45ce42ea53af0ab6569a962d9023cd6e743f8d1ad
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(:as, :class_name, :with, :format)
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
- format = filters_configuration[column.to_sym].fetch(:format, :string)
110
- column_name = filters_configuration[column.to_sym].fetch(:as, column)
111
- klass = filters_configuration[column.to_sym].fetch(:class_name, collection.klass)
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
- predicate = filters_configuration[column.to_sym].fetch(:with, :ilike)
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(klass.table_name.to_sym)
124
+ collection = collection.joins(association_class_or_name)
117
125
  end
118
126
 
119
127
  if %i[between not_between].include?(predicate)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FetcheableOnApi
4
- VERSION = '0.4'.freeze
4
+ VERSION = '0.4.1'.freeze
5
5
  end
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: '0.4'
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-07 00:00:00.000000000 Z
11
+ date: 2020-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport