mongoid-filterable 0.4.1 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71010c85b650681652bd079d24a156341bee7f1f9594d03fe3fd6d1636ab9083
4
- data.tar.gz: 91a7a5441612055ea19400f403d94d934117b39a7d71a110684d2f9d502f1bc8
3
+ metadata.gz: 78743b377f67ff51a0cd93129f3b5a9b975b937e60b6fc12479c09cf3d2f7c8b
4
+ data.tar.gz: b84102c6f3aa6147fcfdd45e008bb48ba708854fc3d023964bb1cacacf27b092
5
5
  SHA512:
6
- metadata.gz: 0fe5207b06afd57c1681131cfb6acd99a87b8acdf66ffb97812f6f81e00dc34a5af512fdb6fc8c1246966ebe5d6ea3a3cafe8180b5fe78a64e6aba21dcbc94ee
7
- data.tar.gz: cbb78b9092a458ca27e75b4ffbc44a29ca0b38fea927a6c6f53c8ce2c04255aa2029efe129535bea351670440f0d3f7e9c83db6904e9fa98ce809c77df9cebc5
6
+ metadata.gz: ea813f93c96f3faf030cf6aa64866b58a947ae5f438cea237a23727ae348f2266ad29918a7ea452be21340e56ad3d409619a681cce461eaa0e9e6cfd1b7868e2
7
+ data.tar.gz: 819e2fb4acbb612df9a79974e488d3f864e6c9e45550ee5ce31611ea772e67e055adc3173f106f033bcd60ca59b8563c29efe321063febff284189a73ca45460
data/README.md CHANGED
@@ -45,6 +45,7 @@ City.create(name: 'city1', people: 100)
45
45
  City.create(name: 'city2', people: 1000)
46
46
  City.filter({name: 'city'}).count # => 2
47
47
  City.filter({name: 'city1'}).count # => 1
48
+ City.filter({name: ''}).count # => 0
48
49
  City.filter({people: 500}) # => 1
49
50
  ```
50
51
 
@@ -7,15 +7,15 @@ module Mongoid
7
7
  ##
8
8
  # Applies params scopes to current scope
9
9
  #
10
- def filter(filtering_params, operator = '$and')
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
- # false is permitted in order to work properly with boolean fields
18
- if (value.present? || value == false) && respond_to?("filter_with_#{key}")
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 = nil)
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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Filterable
3
- VERSION = '0.4.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -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
- {"active" => true, "$and" => [{"code" => :code1}]}
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 ignore filter' do
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(2)
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 ignore filter' do
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(2)
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.1
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-05-22 00:00:00.000000000 Z
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.6
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.