filterameter 0.4.0 → 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: 83338f9a61d92c1d562a5708a0268e647d52916960b4d750a75f3cd6107bee7a
4
- data.tar.gz: a3036ffda002e4075a40be6225681bb67ed9b2f5c2534ecf5370aff70e7d375c
3
+ metadata.gz: 65c8829537f7ee2affcc40a56fb5de2b58d4789fc6d1e9811b33607c86c9c01b
4
+ data.tar.gz: e731021c3cda4e0330b2a7bc499b90ceb49cd918ddd635d57a37c4bf2ce3a9bc
5
5
  SHA512:
6
- metadata.gz: c923a97b54f2da6ed9f2d17743213cde5f16f9525383ef1bbe7081f02ae69ac46553e398a5d5f45b5292f65b84d0a0a681fb198633b06d44eb0ab013a606338c
7
- data.tar.gz: 5dae50a8f42ad0ac9a83dbe497f948f7dbabba29157daf5549478487f6c973a129ee514d04e40820467d3abb8111bf2430d82cf7495bf599e06225f7cb684a4b
6
+ metadata.gz: 20d94a91e915e4f7048db9d11b9608c6f7eaa3d47c018a5ff5132d63736c54e1be96b5ce7f1050325d610c7009e1b64582a2f7253f0cd6a8b37e1e65f4f0f37f
7
+ data.tar.gz: f5aa757afd07c03e2654f11cd34b348c3d0d810231ac9831c82b04e936bb9009fb20f6a8fd93b2193ddfe344481053c0b608d2a074843972d6a35b37f194329a
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/d9d87f9ce8020eb6e656/maintainability)](https://codeclimate.com/github/RockSolt/filterameter/maintainability)
5
5
 
6
6
  # Filterameter
7
- Declarative filter parameters provide provide clean and clear filters for queries.
7
+ Declarative filter parameters provide clean and clear filters for queries.
8
8
 
9
9
  ## Usage
10
10
  Declare filters in query classes or controllers to increase readability and reduce boilerplate code. Filters can be declared for attributes, scopes, or attributes from singular associations (`belongs_to` or `has_one`). Validations can also be assigned.
@@ -170,22 +170,42 @@ Or install it yourself as:
170
170
  $ gem install filterameter
171
171
  ```
172
172
 
173
+ ## Forms and Query Parameters
174
+
175
+ The controller mixin will look for filter parameters nested under the `filter` key. For example, here's what the query parameters might look like for size and color:
176
+
177
+ ```
178
+ ?filter[size]=large&filter[color]=blue
179
+ ```
180
+
181
+ On [a generic search form](https://guides.rubyonrails.org/form_helpers.html#a-generic-search-form), the [`form_with` form helper takes the option `scope`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with) that allows parameters to be grouped:
182
+
183
+ ```erb
184
+ <%= form_with url: "/search", scope: :filter, method: :get do |form| %>
185
+ <%= form.label :size, "Size:" %>
186
+ <%= form.text_field :size %>
187
+ <%= form.label :color, "Color:" %>
188
+ <%= form.text_field :color %>
189
+ <%= form.submit "Search" %>
190
+ <% end %>
191
+ ```
192
+
173
193
 
174
194
  ## Running Tests
175
195
 
176
- Tests are written in RSpec and the dummy app uses a docker database. First, start the database and prepare it from the dummy folder.
196
+ Tests are written in RSpec and the dummy app uses a docker database. The script `bin/start_db.sh` starts and prepares the test
197
+ database. It is a one-time step before running the tests.
177
198
 
178
199
  ```bash
179
- cd spec/dummy
180
- docker-compose up -d
181
- bundle exec rails db:test:prepare
182
- cd ../..
200
+ bin/start_db.rb
201
+ bundle exec rspec
183
202
  ```
184
203
 
185
- Run the tests from the main directory
204
+ The tests can also be run across all the ruby and Rails combinations using appraisal. The install is also a one-time step.
186
205
 
187
206
  ```bash
188
- bundle exec rspec
207
+ bundle exec appraisal install
208
+ bundle exec appraisal rspec
189
209
  ```
190
210
 
191
211
  ## License
@@ -64,15 +64,7 @@ module Filterameter
64
64
  raise Filterameter::Exceptions::ValidationError, validator.errors
65
65
  end
66
66
 
67
- filter_params.except(*invalid_attributes(validator.errors).map(&:to_s))
68
- end
69
-
70
- def invalid_attributes(errors)
71
- if errors.respond_to? :attribute_names
72
- errors.attribute_names
73
- else # pre rails 6.1
74
- errors.keys
75
- end
67
+ filter_params.except(*validator.errors.attribute_names.map(&:to_s))
76
68
  end
77
69
 
78
70
  def validator_class
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filterameter
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterameter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-15 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '4.0'
103
+ version: '6.1'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '4.0'
110
+ version: '6.1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +171,6 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
- - MIT-LICENSE
175
174
  - README.md
176
175
  - Rakefile
177
176
  - lib/filterameter.rb
@@ -222,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
221
  - !ruby/object:Gem::Version
223
222
  version: '0'
224
223
  requirements: []
225
- rubygems_version: 3.4.10
224
+ rubygems_version: 3.4.19
226
225
  signing_key:
227
226
  specification_version: 4
228
227
  summary: Declarative Filter Parameters
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2019 Todd Kummer
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.