filterameter 1.0.1 → 1.0.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
  SHA256:
3
- metadata.gz: a250b39d9c80245166bcfe14a7133cd5ec83f9746989d7e461fa0c121358f57a
4
- data.tar.gz: 5d7c64cb79fd73ee94e4e94316b0b5964fac440b14fb0bc58c0c1d805d0f9d60
3
+ metadata.gz: 50c824121830196b05ccb71f43495ad4d5197f85fe9d31456edc549fd2462a59
4
+ data.tar.gz: 4bb268b89c285e6542b0347bb3c52ca903f4d9be517f33b6303a76200b36f6c6
5
5
  SHA512:
6
- metadata.gz: d170eb98f80c24173fa92d0251aa68af7d5f3d002d4c3ff473e086aba8d16f07fd05422af6dced018331e883431c93292b4d0b7e5bf3476587b40df8dbeab8d3
7
- data.tar.gz: e2342236255b79da8ee96aa7eec0e33c6e9f0131473eaadffd31f833c7212d01d2123eeb6a70cdff8d619ff8678f4d6aafc8d9b52151de9dc6583983f3accd92
6
+ metadata.gz: 21e92b0610890ed0ccbd8e3bdba68864de0c28d1c1ea42af40e51e696b0950c0ed6dd2d085673e493f400ca875d0307eeaaf9b844d021f1ae0d2fe11d53420c7
7
+ data.tar.gz: 77edd1277a98e49ab6c6425fe387404176477afc9050bafbb4d3d0eb34268d0e0e4a1f2983fb3b4951a0c9e7c88a0309464ab11112d67ae401ebcb75f7a74617
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/filterameter.svg)](https://badge.fury.io/rb/filterameter)
2
2
  [![RuboCop](https://github.com/RockSolt/filterameter/workflows/RuboCop/badge.svg)](https://github.com/RockSolt/filterameter/actions?query=workflow%3ARuboCop)
3
3
  [![RSpec](https://github.com/RockSolt/filterameter/workflows/RSpec/badge.svg)](https://github.com/RockSolt/filterameter/actions?query=workflow%3ARSpec)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/d9d87f9ce8020eb6e656/maintainability)](https://codeclimate.com/github/RockSolt/filterameter/maintainability)
5
4
 
6
5
  # Filterameter
7
6
  Filterameter provides declarative filters for Rails controllers to reduce boilerplate code and increase readability. How many times have you seen (or written) this controller action?
@@ -147,7 +146,7 @@ There are two shortcuts: : the partial option can be declared with `true`, which
147
146
  ```ruby
148
147
  filter :description, partial: true
149
148
  filter :department_name, partial: :from_start
150
- filter :reason, partial: { match: :dynamic, case_sensitive: true }
149
+ filter :reason, partial: { match: :dynamic, case_sensitive: true }
151
150
  ```
152
151
 
153
152
  The `match` options defines where you are searching (which then controls where the wildcard(s) appear):
@@ -247,10 +246,10 @@ end
247
246
 
248
247
  #### Default Sort
249
248
 
250
- A default sort can be declared using `default_sort`. The argument(s) should specify one or more of the declared sorts or sortable filters by name. By default, the order is ascending. If you want descending order, you can map the column name symbol to :desc.
249
+ A default sort can be declared using `default_sort`. The argument(s) should specify one or more of the declared sorts or sortable filters by name. The sorts should be defined as key-value pairs, with the name as the key and the direction as the value.
251
250
 
252
251
  ```ruby
253
- default_sort updated_at: :desc, :description
252
+ default_sort updated_at: :desc, description: :asc
254
253
  ```
255
254
 
256
255
  In order to provide consistent results, a sort is always applied. If no default is specified, it will use primary key descending.
@@ -267,7 +266,7 @@ There are two ways to apply the filters and build the query, depending on how mu
267
266
 
268
267
  Add before action callback `build_filtered_query` for controller actions that should build the query. This can be done either in the `ApplicationController` or on a case-by-case basis.
269
268
 
270
- When using the callback, the variable name is the pluralized model name. For example, the Photo model will use the variable `@photos` to store the query. The variable name can be explicitly specified with with `filter_query_var_name`. For example, if the query is stored as `@data`, use the following:
269
+ When using the callback, the variable name is the pluralized model name. For example, the Photo model will use the variable `@photos` to store the query. The variable name can be explicitly specified with `filter_query_var_name`. For example, if the query is stored as `@data`, use the following:
271
270
 
272
271
  ```ruby
273
272
  filter_query_var_name :data
@@ -338,7 +337,7 @@ Note that the starting query provides the model, so the model is not looked up a
338
337
 
339
338
  ### Specifying the Model
340
339
 
341
- Rails conventions are used to determine the controller's model. For example, the PhotosController builds a query against the Photo model. If a controller is namespaced, the model will first be looked up without the namespace, then with the namespace.
340
+ Rails conventions are used to determine the controller's model. For example, the PhotosController builds a query against the Photo model. If a controller is namespaced, the model will first be looked up without the namespace, then with the namespace.
342
341
 
343
342
  **If the conventions do not provide the correct model**, the model can be named explicitly with the following:
344
343
 
@@ -356,7 +355,7 @@ There are three configuration options:
356
355
  - action_on_validation_failure
357
356
  - filter_key
358
357
 
359
- The configuration options can be set in an initializer, an environment file, or in `application.rb`.
358
+ The configuration options can be set in an initializer, an environment file, or in `application.rb`.
360
359
 
361
360
  The options can be set directly...
362
361
 
@@ -367,7 +366,7 @@ The options can be set directly...
367
366
  ```ruby
368
367
  Filterameter.configure do |config|
369
368
  config.action_on_undeclared_parameters = :log
370
- config.action_on_validation_failuer = :log
369
+ config.action_on_validation_failure = :log
371
370
  config.filter_key = :f
372
371
  end
373
372
  ```
@@ -433,7 +432,7 @@ The sort is also nested underneath the filter key:
433
432
 
434
433
  Use an array to pass multiple sorts. The order of the parameters is the order the sorts will be applied. For example, the following sorts first by size then by color:
435
434
 
436
- `/widgets?filter[sort]=size&filter[sort]=color`
435
+ `/widgets?filter[sort][]=size&filter[sort][]=color`
437
436
 
438
437
  Sorts are ascending by default, but can use a prefix can be added to control the sort:
439
438
 
@@ -446,7 +445,7 @@ For example, the following sorts by size descending:
446
445
 
447
446
  ## Contribute
448
447
 
449
- Feedback, feature requests, and proposed changes are welcomed. Please use the [issue tracker](https://github.com/RockSolt/filterameter/issues)
448
+ Feedback, feature requests, and proposed changes are welcomed. Please use the [issue tracker](https://github.com/RockSolt/filterameter/issues)
450
449
  for feedback and feature requests. To propose a change directly, please fork the repo and open a pull request. Keep an eye on the actions to make
451
450
  sure the tests and Rubocop are passing. [Code Climate](https://codeclimate.com/github/RockSolt/filterameter) is also used manually to assess the codeline.
452
451
 
@@ -460,11 +459,10 @@ Gold stars will be awarded if you are able to [replicate the issue with a test](
460
459
 
461
460
  ### Running Tests
462
461
 
463
- Tests are written in RSpec and the dummy app uses a docker database. The script `bin/start_db.sh` starts and prepares the test
464
- database. It is a one-time step before running the tests.
462
+ Tests are written in RSpec.
465
463
 
466
464
  ```bash
467
- bin/start_db.rb
465
+ bin/prepare_db.sh
468
466
  bundle exec rspec
469
467
  ```
470
468
 
@@ -93,9 +93,10 @@ module Filterameter
93
93
 
94
94
  # Declares a list of sorts without options. Sorts that require options must be declared with `sort`.
95
95
  def sorts(*parameter_names)
96
- parameter_names.each { |parameter_name| filter(parameter_name) }
96
+ parameter_names.each { |parameter_name| sort(parameter_name) }
97
97
  end
98
98
 
99
+ # Declares a default sort order for the query. Specify a list of sort names and directions as pairs.
99
100
  def default_sort(sort_and_direction_pairs)
100
101
  filter_coordinator.default_sort = sort_and_direction_pairs
101
102
  end
@@ -30,7 +30,9 @@ module Filterameter
30
30
 
31
31
  def parse_filter_params(filter_params)
32
32
  sort = parse_sorts(filter_params.delete('sort'))
33
- [sort, remove_invalid_values(filter_params)]
33
+ params = filter_params.reject { |_k, v| v.is_a?(String) && v.empty? }
34
+ .then { |p| remove_invalid_values(p) }
35
+ [sort, params]
34
36
  end
35
37
 
36
38
  def parse_sorts(sorts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filterameter
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.3'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterameter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-09 00:00:00.000000000 Z
10
+ date: 2026-03-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -37,62 +37,6 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: 2.5.0
40
- - !ruby/object:Gem::Dependency
41
- name: guard
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '2.16'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '2.16'
54
- - !ruby/object:Gem::Dependency
55
- name: guard-rspec
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '4.7'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '4.7'
68
- - !ruby/object:Gem::Dependency
69
- name: guard-rubocop
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: 1.5.0
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: 1.5.0
82
- - !ruby/object:Gem::Dependency
83
- name: pg
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: 1.5.4
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: 1.5.4
96
40
  - !ruby/object:Gem::Dependency
97
41
  name: rspec-rails
98
42
  requirement: !ruby/object:Gem::Requirement
@@ -127,14 +71,14 @@ dependencies:
127
71
  requirements:
128
72
  - - "~>"
129
73
  - !ruby/object:Gem::Version
130
- version: 0.5.2
74
+ version: '0.6'
131
75
  type: :development
132
76
  prerelease: false
133
77
  version_requirements: !ruby/object:Gem::Requirement
134
78
  requirements:
135
79
  - - "~>"
136
80
  - !ruby/object:Gem::Version
137
- version: 0.5.2
81
+ version: '0.6'
138
82
  - !ruby/object:Gem::Dependency
139
83
  name: rubocop-rails
140
84
  requirement: !ruby/object:Gem::Requirement
@@ -155,28 +99,28 @@ dependencies:
155
99
  requirements:
156
100
  - - "~>"
157
101
  - !ruby/object:Gem::Version
158
- version: 3.2.0
102
+ version: '3.9'
159
103
  type: :development
160
104
  prerelease: false
161
105
  version_requirements: !ruby/object:Gem::Requirement
162
106
  requirements:
163
107
  - - "~>"
164
108
  - !ruby/object:Gem::Version
165
- version: 3.2.0
109
+ version: '3.9'
166
110
  - !ruby/object:Gem::Dependency
167
111
  name: rubocop-rspec_rails
168
112
  requirement: !ruby/object:Gem::Requirement
169
113
  requirements:
170
114
  - - "~>"
171
115
  - !ruby/object:Gem::Version
172
- version: 2.30.0
116
+ version: '2.32'
173
117
  type: :development
174
118
  prerelease: false
175
119
  version_requirements: !ruby/object:Gem::Requirement
176
120
  requirements:
177
121
  - - "~>"
178
122
  - !ruby/object:Gem::Version
179
- version: 2.30.0
123
+ version: '2.32'
180
124
  - !ruby/object:Gem::Dependency
181
125
  name: simplecov
182
126
  requirement: !ruby/object:Gem::Requirement
@@ -267,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
211
  - !ruby/object:Gem::Version
268
212
  version: '0'
269
213
  requirements: []
270
- rubygems_version: 3.6.2
214
+ rubygems_version: 3.6.9
271
215
  specification_version: 4
272
216
  summary: Declarative Filter Parameters
273
217
  test_files: []