filtering 0.1.0 → 0.1.1
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/Gemfile.lock +35 -0
- data/README.md +8 -8
- data/lib/filtering/base.rb +2 -2
- data/lib/filtering/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d10e915ebf65faf4e5bde4d5757bf482638c2c6
|
4
|
+
data.tar.gz: c1aae098a832689f11562c4a04a760cc67ad702f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 747eaed5311cc56b010dca7b3b40b9bdd9b84deea49df1d07a5e132730d05638d6efaf67aca14500e6d680185b15e58426aca607394e5647bf20cc8b372ddf92
|
7
|
+
data.tar.gz: 5ad728b74ae091db15c3432cb5168e01d8adc1b71b9594eec68db9ac707e3e90639f852eb46d81f5e57ff836e0d6c3ab22e887c9533b642f355d72062a915a46
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
filtering (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
filtering!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ All you need to do is inherit custom filter service from `Filtering::Base` and d
|
|
24
24
|
### Example filter service
|
25
25
|
|
26
26
|
```
|
27
|
-
class Filters::
|
27
|
+
class Filters::UsersFilter < Filtering::Base
|
28
28
|
def initialize(params, page)
|
29
29
|
super(params, page)
|
30
30
|
end
|
@@ -37,7 +37,7 @@ class Filters::OffersFilter < Filtering::Base
|
|
37
37
|
User.all
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def plain_acessible_params
|
41
41
|
%i[city age]
|
42
42
|
end
|
43
43
|
|
@@ -53,23 +53,23 @@ class Filters::OffersFilter < Filtering::Base
|
|
53
53
|
end
|
54
54
|
|
55
55
|
```
|
56
|
-
There are
|
56
|
+
There are private methods:
|
57
57
|
|
58
58
|
`relation` is an ActiveRecord initial relation which must be filtered
|
59
59
|
|
60
|
-
`plain_acessible_params` array of params for auto-filtering by `where`, so if you have `%i[city age]` will be called `User.where(city: city).where(age: age)`
|
60
|
+
`plain_acessible_params` array of params for an auto-filtering by `where`, so if you have `%i[city age]` will be called `User.where(city: city).where(age: age)`
|
61
61
|
|
62
|
-
`complex_acessible_params` array of params for filters with custom logic. If you have some params in that method you have to create methods for those custom filters
|
62
|
+
`complex_acessible_params` array of params for filters with custom logic. If you have some params in that method you have to create methods for those custom filters with format: `filter_by_{param}`
|
63
63
|
|
64
64
|
### Calling
|
65
|
-
|
65
|
+
Controller usage example:
|
66
66
|
|
67
67
|
```
|
68
68
|
def index
|
69
|
-
render json: Filters::
|
69
|
+
render json: Filters::UsersFilter.new(params, page: params[:page]).call
|
70
70
|
end
|
71
71
|
```
|
72
|
-
If you don't use
|
72
|
+
If you don't use Kaminari just delete page from initializer
|
73
73
|
|
74
74
|
## License
|
75
75
|
|
data/lib/filtering/base.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Filtering::Base
|
2
|
-
def initialize(params,
|
2
|
+
def initialize(params, args = {})
|
3
3
|
@plain_params = params.permit(plain_acessible_params)
|
4
4
|
@complex_params = params.permit(complex_acessible_params)
|
5
|
-
@page = page
|
5
|
+
@page = args[:page]
|
6
6
|
@results = relation
|
7
7
|
end
|
8
8
|
|
data/lib/filtering/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filtering
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaliy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ".travis.yml"
|
65
65
|
- CODE_OF_CONDUCT.md
|
66
66
|
- Gemfile
|
67
|
+
- Gemfile.lock
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|
69
70
|
- Rakefile
|