mongoid-filterable 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +9 -9
- data/lib/mongoid-filterable/filterable.rb +1 -1
- data/lib/mongoid-filterable/version.rb +1 -1
- data/spec/filterable_spec.rb +22 -22
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee668ea1b497adc91c147956f1f390abf02038e6b9968dff39345c1c3901c0be
|
4
|
+
data.tar.gz: 0f94be3a0505256cb8bd205c281ed5a2beb239262c05528efd71876aa5516360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 265830fc7d04d50f90e2d19907baeeb7e6fc324e297f3b21108022ac6606d0881b6a967566db18f133e80090b0d6b7eb1b40198847a5dff631a931ac9d8477a8
|
7
|
+
data.tar.gz: a4fc72a06601a609655d67ff7276fd8e7ccf11f1ccc533641445681fab98f8baa900986db840a61d5928c365c955326b4bfb08e18aceee453256b636ac94131d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -43,10 +43,10 @@ end
|
|
43
43
|
|
44
44
|
City.create(name: 'city1', people: 100)
|
45
45
|
City.create(name: 'city2', people: 1000)
|
46
|
-
City.
|
47
|
-
City.
|
48
|
-
City.
|
49
|
-
City.
|
46
|
+
City.filtrate({name: 'city'}).count # => 2
|
47
|
+
City.filtrate({name: 'city1'}).count # => 1
|
48
|
+
City.filtrate({name: ''}).count # => 0
|
49
|
+
City.filtrate({people: 500}) # => 1
|
50
50
|
```
|
51
51
|
|
52
52
|
#### Operator
|
@@ -57,8 +57,8 @@ You can specify selector operator:
|
|
57
57
|
* $or
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
City.
|
61
|
-
City.
|
60
|
+
City.filtrate({name: 'city1', people: 1000}, '$and').count # => 0
|
61
|
+
City.filtrate({name: 'city1', people: 1000}, '$or').count # => 1
|
62
62
|
```
|
63
63
|
|
64
64
|
#### Range
|
@@ -66,7 +66,7 @@ City.filter({name: 'city1', people: 1000}, '$or').count # => 1
|
|
66
66
|
Searches with more than one param is also available:
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
City.
|
69
|
+
City.filtrate(people_range: [500, 1000]).count # => 1
|
70
70
|
```
|
71
71
|
|
72
72
|
#### Rails controller
|
@@ -74,7 +74,7 @@ City.filter(people_range: [500, 1000]).count # => 1
|
|
74
74
|
```ruby
|
75
75
|
class CitiesController
|
76
76
|
def index
|
77
|
-
respond_with City.
|
77
|
+
respond_with City.filtrate(filter_params)
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
@@ -101,7 +101,7 @@ end
|
|
101
101
|
|
102
102
|
City.create(name: 'Cíty1')
|
103
103
|
City.create(name: 'Cíty2')
|
104
|
-
City.
|
104
|
+
City.filtrate({name: 'city1'}).count # => 1
|
105
105
|
```
|
106
106
|
|
107
107
|
## Contributing
|
data/spec/filterable_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe Mongoid::Filterable do
|
|
31
31
|
|
32
32
|
context 'when use default operator' do
|
33
33
|
it 'should create correct selector' do
|
34
|
-
expect(City.
|
34
|
+
expect(City.filtrate(code: :code1).selector).to eq(
|
35
35
|
'active' => true, '$and' => [{'code' => :code1}]
|
36
36
|
)
|
37
37
|
end
|
@@ -39,38 +39,38 @@ describe Mongoid::Filterable do
|
|
39
39
|
it 'should filter by default filter' do
|
40
40
|
City.create(code: :code1)
|
41
41
|
City.create(code: :code2)
|
42
|
-
expect(City.
|
43
|
-
expect(City.
|
42
|
+
expect(City.filtrate(code: :code1).count).to eq(1)
|
43
|
+
expect(City.filtrate(code: :code1).first.code).to eq(:code1)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should filter by match filter' do
|
47
47
|
City.create(name: 'city1')
|
48
48
|
City.create(name: 'city2')
|
49
|
-
expect(City.
|
50
|
-
expect(City.
|
51
|
-
expect(City.
|
49
|
+
expect(City.filtrate(name: 'city').count).to eq(2)
|
50
|
+
expect(City.filtrate(name: 'city1').count).to eq(1)
|
51
|
+
expect(City.filtrate(name: 'city1').first.name).to eq('city1')
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should filter by custom filter' do
|
55
55
|
City.create(people: 100)
|
56
56
|
City.create(people: 1000)
|
57
|
-
expect(City.
|
58
|
-
expect(City.
|
57
|
+
expect(City.filtrate(people: 500).count).to eq(1)
|
58
|
+
expect(City.filtrate(people: 500).first.people).to eq(1000)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should filter by normalized filter' do
|
62
62
|
City.create(country_normalized: 'spain')
|
63
63
|
City.create(country_normalized: 'france')
|
64
|
-
expect(City.
|
65
|
-
expect(City.
|
64
|
+
expect(City.filtrate(country: 'spain').count).to eq(1)
|
65
|
+
expect(City.filtrate(country: 'spain').first.country_normalized).to eq('spain')
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should respect previous selector' do
|
69
69
|
City.create(name: 'city1', people: 100)
|
70
70
|
City.create(name: 'city2', people: 1000)
|
71
71
|
City.create(name: 'city3', people: 2000)
|
72
|
-
expect(City.where(name: 'city2').
|
73
|
-
expect(City.where(name: 'city2').
|
72
|
+
expect(City.where(name: 'city2').filtrate(people: '500').count).to eq(1)
|
73
|
+
expect(City.where(name: 'city2').filtrate(people: '500').first.name).to eq('city2')
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,7 +78,7 @@ describe Mongoid::Filterable do
|
|
78
78
|
it 'should filter using and query' do
|
79
79
|
City.create(name: 'city1', people: 100)
|
80
80
|
City.create(name: 'city2', people: 2000)
|
81
|
-
expect(City.
|
81
|
+
expect(City.filtrate({name: 'city1', people: '2000'}, '$and').count).to eq(0)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -86,7 +86,7 @@ describe Mongoid::Filterable do
|
|
86
86
|
it 'should filter using or query' do
|
87
87
|
City.create(name: 'city1', people: 100)
|
88
88
|
City.create(name: 'city2', people: 2000)
|
89
|
-
expect(City.
|
89
|
+
expect(City.filtrate({name: 'city1', people: '2000'}, '$or').count).to eq(1)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -94,7 +94,7 @@ describe Mongoid::Filterable do
|
|
94
94
|
it 'should ignore filter' do
|
95
95
|
City.create(name: 'city1')
|
96
96
|
City.create(name: 'city2')
|
97
|
-
expect(City.
|
97
|
+
expect(City.filtrate(invalid: 'val').count).to eq(2)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -102,7 +102,7 @@ describe Mongoid::Filterable do
|
|
102
102
|
it 'should ignore filter' do
|
103
103
|
City.create(name: 'city1')
|
104
104
|
City.create(name: 'city2')
|
105
|
-
expect(City.
|
105
|
+
expect(City.filtrate(nil).count).to eq(2)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -112,7 +112,7 @@ describe Mongoid::Filterable do
|
|
112
112
|
City.create(people: 500)
|
113
113
|
City.create(people: 1000)
|
114
114
|
City.create(people: 1000)
|
115
|
-
expect(City.
|
115
|
+
expect(City.filtrate(people_range: [500, 1000]).count).to eq(3)
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'does not break compatibility with filters receiving only one param as array' do
|
@@ -120,7 +120,7 @@ describe Mongoid::Filterable do
|
|
120
120
|
City.create(people: 500)
|
121
121
|
City.create(people: 1000)
|
122
122
|
City.create(people: 1000)
|
123
|
-
expect(City.
|
123
|
+
expect(City.filtrate(people_in: [500, 100]).count).to eq(2)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -128,7 +128,7 @@ describe Mongoid::Filterable do
|
|
128
128
|
it 'should apply filter' do
|
129
129
|
City.create(people: 100)
|
130
130
|
City.create(people: 500)
|
131
|
-
expect(City.
|
131
|
+
expect(City.filtrate(people: nil).count).to eq(0)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -136,7 +136,7 @@ describe Mongoid::Filterable do
|
|
136
136
|
it 'should apply filter' do
|
137
137
|
City.create(people: 100)
|
138
138
|
City.create(people: 500)
|
139
|
-
expect(City.
|
139
|
+
expect(City.filtrate(people: '').count).to eq(0)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -144,7 +144,7 @@ describe Mongoid::Filterable do
|
|
144
144
|
it 'should filter using a query' do
|
145
145
|
City.create(name: 'city1')
|
146
146
|
City.create(name: 'city2', active: false)
|
147
|
-
expect(City.unscoped.
|
147
|
+
expect(City.unscoped.filtrate(active: false).count).to eq(1)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -154,7 +154,7 @@ describe Mongoid::Filterable do
|
|
154
154
|
City.create(name: '1', people: 500)
|
155
155
|
City.create(name: '1', people: 1000)
|
156
156
|
City.create(name: '1', people: 1000)
|
157
|
-
expect(City.where(name: '2').
|
157
|
+
expect(City.where(name: '2').filtrate(nil).count).to eq(1)
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-filterable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Jurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.3
|
116
|
+
rubygems_version: 3.0.1
|
118
117
|
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: Easy way to add scopes to your models.
|