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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -17
  3. data/lib/qry_filter/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17501b95f2d0615442a1b81056df65461f31c31263f508e5458898162df6bb91
4
- data.tar.gz: e759286af0273f0b89df702ba2a396b622e6856175f874f31027fff9b12ad9c1
3
+ metadata.gz: 60ab5cc64d73a67de92abde0aaef2a9390b82beb64dcf70a64b706c7b94ac812
4
+ data.tar.gz: 4a5c753b591b8ade82a85989ee85ad3ec87b2908b0782bc4f3bb647c808f210c
5
5
  SHA512:
6
- metadata.gz: 8795ad6c170e0f5d27f4ac359ac58a85f8951f4faf246eba3e27eb49d34ca22aab95074d730b9b9e0cd6de46dc7415b3b506c06bda273a45da68fdabe3d56ed8
7
- data.tar.gz: 654164d8518af4e6cb858ac469f9f25ffc9d6832ec855c668a16007720e4b40f1f58a5b3d68f2b8678235a624df1aa5d1edf7517f61e6fbd527f35f7f4feab9a
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
- **Class Method**
24
+ **In Controller**
27
25
  ```ruby
28
- QryFilter.compose(scope, params)
29
- QryFilter.compose(scope, params, filter_by: [:id, :age])
30
- QryFilter.compose(scope, params, filter_by: [:id, :age], filter_class: UserFilter)
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
- **Helper**
35
+ **Other options**
36
+
37
+ Class Method:
34
38
  ```ruby
35
- filter scope, params
36
- filter scope, params, filter_by: [:id, :age]
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
- ## TODO
41
- - Autodetect Model name to match with Filter class
42
- - Work with ActiveRecord::Relation
43
- - Generator for ApplicationFilter
44
- - More tests
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
 
@@ -1,3 +1,3 @@
1
1
  module QryFilter
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-06 00:00:00.000000000 Z
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/ibarrain/qry_filter
71
+ homepage: https://github.com/inaki-ibarra/qry_filter
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}