qry_filter 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +32 -17
- data/lib/qry_filter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ab5cc64d73a67de92abde0aaef2a9390b82beb64dcf70a64b706c7b94ac812
|
4
|
+
data.tar.gz: 4a5c753b591b8ade82a85989ee85ad3ec87b2908b0782bc4f3bb647c808f210c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eceb727a88db6521fc2c8f5d8a79a01b915004ed1d6a6e38383832c853e6456f95e6dff129fdd66c52426c8743133ac822b6d0518cd067d53834c16513bbd68
|
7
|
+
data.tar.gz: 34c55324984dc9dff118d58beb9dbb33cd530e8b0884a77f4d9d310f483186147f039623951087a4991a7f6b6a9baf24bd0690620d38b10fc36107c130eb140c
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# QryFilter
|
2
|
-
*Note: This is a work in progress and should not be used in production.*
|
3
|
-
|
4
2
|
QryFilter aka "QueryFilter" is a simple Rails gem that provides a pattern and helper when dealing with lots of filter clauses in your ActiveRecord query.
|
5
3
|
|
6
4
|
## Usage
|
@@ -23,25 +21,35 @@ class UserFilter < ApplicationFilter
|
|
23
21
|
end
|
24
22
|
```
|
25
23
|
|
26
|
-
**
|
24
|
+
**In Controller**
|
27
25
|
```ruby
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# app/controllers/user_controller.rb
|
27
|
+
class UsersController < ApplicationController
|
28
|
+
def index
|
29
|
+
users = filter User, params
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
end
|
31
33
|
```
|
32
34
|
|
33
|
-
**
|
35
|
+
**Other options**
|
36
|
+
|
37
|
+
Class Method:
|
34
38
|
```ruby
|
35
|
-
|
36
|
-
|
37
|
-
filter scope, params, filter_by: [:id, :age], filter_class: UserFilter
|
38
|
-
```
|
39
|
+
params = {id: [1, 2, 3], age: [18, 20]}
|
40
|
+
users = User.where(happy: true)
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
QryFilter.compose(users, params, filter_by: [:id, :age], filter_class: UserFilter)
|
43
|
+
```
|
44
|
+
Helper:
|
45
|
+
```ruby
|
46
|
+
filter User, params, filter_by: [:id, :age], filter_class: UserFilter
|
47
|
+
```
|
48
|
+
- The first argument accepts ActiveRecord::Relation or model class name.
|
49
|
+
- The second is for key-value pair of data you want to pass to your filter class.
|
50
|
+
- The last argument is a hash and allows you to set ```filter_by``` and ```filter_class```
|
51
|
+
- ```filter_by``` maps with your filter class methods e.g. ```[:id]``` will only trigger ```by_id``` method.
|
52
|
+
- ```filter_class``` allows you to set a specific class when needed.
|
45
53
|
|
46
54
|
## Installation
|
47
55
|
Add this line to your application's Gemfile:
|
@@ -60,11 +68,18 @@ Or install it yourself as:
|
|
60
68
|
$ gem install qry_filter
|
61
69
|
```
|
62
70
|
|
63
|
-
Generate app/filters/application_filter.rb:
|
71
|
+
Generate app/filters/application_filter.rb:
|
64
72
|
```bash
|
65
73
|
$ rails g qry_filter:install
|
66
74
|
```
|
67
75
|
|
76
|
+
Include QryFilter in ApplicationController
|
77
|
+
```ruby
|
78
|
+
class ApplicationController < ActionController::Base
|
79
|
+
include QryFilter
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
68
83
|
## Contributing
|
69
84
|
Contribution directions go here.
|
70
85
|
|
data/lib/qry_filter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qry_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iñaki Ibarra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -68,7 +68,7 @@ files:
|
|
68
68
|
- lib/qry_filter.rb
|
69
69
|
- lib/qry_filter/filter_class_finder.rb
|
70
70
|
- lib/qry_filter/version.rb
|
71
|
-
homepage: https://github.com/
|
71
|
+
homepage: https://github.com/inaki-ibarra/qry_filter
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
74
|
metadata: {}
|