mongoid-filterable 0.4.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/mongoid-filterable/filterable.rb +4 -4
- data/lib/mongoid-filterable/version.rb +1 -1
- data/spec/filterable_spec.rb +5 -5
- 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: 78743b377f67ff51a0cd93129f3b5a9b975b937e60b6fc12479c09cf3d2f7c8b
|
4
|
+
data.tar.gz: b84102c6f3aa6147fcfdd45e008bb48ba708854fc3d023964bb1cacacf27b092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea813f93c96f3faf030cf6aa64866b58a947ae5f438cea237a23727ae348f2266ad29918a7ea452be21340e56ad3d409619a681cce461eaa0e9e6cfd1b7868e2
|
7
|
+
data.tar.gz: 819e2fb4acbb612df9a79974e488d3f864e6c9e45550ee5ce31611ea772e67e055adc3173f106f033bcd60ca59b8563c29efe321063febff284189a73ca45460
|
data/README.md
CHANGED
@@ -7,15 +7,15 @@ module Mongoid
|
|
7
7
|
##
|
8
8
|
# Applies params scopes to current scope
|
9
9
|
#
|
10
|
-
def filter(filtering_params, operator
|
10
|
+
def filter(filtering_params, operator='$and')
|
11
11
|
return all unless filtering_params
|
12
12
|
results = all
|
13
13
|
selectors = []
|
14
14
|
criteria = unscoped
|
15
15
|
|
16
16
|
filtering_params.each do |key, value|
|
17
|
-
#
|
18
|
-
|
17
|
+
if respond_to?("filter_with_#{key}")
|
18
|
+
# check the number of arguments of filter scope
|
19
19
|
if value.is_a?(Array) && scopes["filter_with_#{key}".to_sym][:scope].arity > 1
|
20
20
|
selectors.push criteria.public_send("filter_with_#{key}", *value).selector
|
21
21
|
else
|
@@ -30,7 +30,7 @@ module Mongoid
|
|
30
30
|
##
|
31
31
|
# Adds attr scope
|
32
32
|
#
|
33
|
-
def filter_by(attr, filter
|
33
|
+
def filter_by(attr, filter=nil)
|
34
34
|
if filter
|
35
35
|
scope "filter_with_#{attr}", filter
|
36
36
|
elsif fields[attr.to_s].type == String
|
data/spec/filterable_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe Mongoid::Filterable do
|
|
32
32
|
context 'when use default operator' do
|
33
33
|
it 'should create correct selector' do
|
34
34
|
expect(City.filter(code: :code1).selector).to eq(
|
35
|
-
|
35
|
+
'active' => true, '$and' => [{'code' => :code1}]
|
36
36
|
)
|
37
37
|
end
|
38
38
|
|
@@ -125,18 +125,18 @@ describe Mongoid::Filterable do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
context 'when value is nil' do
|
128
|
-
it 'should
|
128
|
+
it 'should apply filter' do
|
129
129
|
City.create(people: 100)
|
130
130
|
City.create(people: 500)
|
131
|
-
expect(City.filter(people: nil).count).to eq(
|
131
|
+
expect(City.filter(people: nil).count).to eq(0)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
context 'when value is empty string' do
|
136
|
-
it 'should
|
136
|
+
it 'should apply filter' do
|
137
137
|
City.create(people: 100)
|
138
138
|
City.create(people: 500)
|
139
|
-
expect(City.filter(people: '').count).to eq(
|
139
|
+
expect(City.filter(people: '').count).to eq(0)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
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: 0.
|
4
|
+
version: 1.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: 2018-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.7.
|
117
|
+
rubygems_version: 2.7.3
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Easy way to add scopes to your models.
|