mongoid-filterable 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 112246751dd972a531a49a44a390f5410c5e4381
4
- data.tar.gz: 88a7ccd863fe6c8c0caef1622bf961150d3d53c4
3
+ metadata.gz: 0cc104bbb65a8e42e77d115ebf48120f5900db83
4
+ data.tar.gz: df3d3174ae73e49df358eef8184abaa4ca3eb608
5
5
  SHA512:
6
- metadata.gz: 46e4dfeec6248cf4d023d68c6d555aea1ff3ab40388181b0c3e964ff08cadd69ef5a77c7890c09d11fa141f482424612804f656fe63b059eda18f27dc59eda8c
7
- data.tar.gz: 5c9db4c56af8acb8de1f93cb4945c2070973b42e226fcf436e752b971f362406e5bcc62aa584a8c8aeb715f677f9d3ff0ea9589b4fefc2f71c8e6ad3c0b12130
6
+ metadata.gz: 6b08758991202f1d3a837c4877e1a908a49882a045ab6f0893a905167b0fb68bf79f1c2e0d835e367554c59c8d217b75a73bd3deb6c97d1379cd2e3ab9b3446b
7
+ data.tar.gz: 697ad7e99e925c6e18016b9a108be61a03b33efd8d42033f951f9273f80afb1f7c8e506a8c0a2255c8fd0a956ef087f67c34d7378fdfc2e68d7847ccc6f585e6
data/README.md CHANGED
@@ -34,6 +34,7 @@ end
34
34
 
35
35
  City.create(name: 'city1', people: 100)
36
36
  City.create(name: 'city2', people: 1000)
37
+ City.filter({name: 'city'}).count # => 2
37
38
  City.filter({name: 'city1'}).count # => 1
38
39
  City.filter({people: 500}) # => 1
39
40
  ```
@@ -77,7 +78,7 @@ class City
77
78
  field :name
78
79
  normalize :name
79
80
 
80
- filter_by_normalize(:name)
81
+ filter_by_normalized(:name)
81
82
  end
82
83
 
83
84
  City.create(name: 'Cíty1')
@@ -26,7 +26,11 @@ module Mongoid
26
26
  if filter
27
27
  self.scope "filter_with_#{attr}", filter
28
28
  else
29
- self.scope "filter_with_#{attr}", lambda{ |value| where(attr => value)}
29
+ if self.fields[attr.to_s].type == String
30
+ self.scope "filter_with_#{attr}", lambda{ |value| where(attr => Regexp.new(value)) }
31
+ else
32
+ self.scope "filter_with_#{attr}", lambda{ |value| where(attr => value) }
33
+ end
30
34
  end
31
35
  end
32
36
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Filterable
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -5,11 +5,13 @@ describe Mongoid::Filterable do
5
5
  include Mongoid::Document
6
6
  include Mongoid::Filterable
7
7
 
8
- field :name
9
- field :people
8
+ field :name, type: String
9
+ field :code, type: Symbol
10
+ field :people, type: Integer
10
11
  field :country_normalized
11
12
 
12
13
  filter_by(:name)
14
+ filter_by(:code)
13
15
  filter_by(:people, lambda{|value| where(:people.gt => value)})
14
16
  filter_by_normalized(:country)
15
17
  end
@@ -20,8 +22,16 @@ describe Mongoid::Filterable do
20
22
 
21
23
  context 'when use default operator' do
22
24
  it 'should filter by default filter' do
25
+ City.create(code: :code1)
26
+ City.create(code: :code2)
27
+ expect(City.filter({code: :code1}).count).to eq(1)
28
+ expect(City.filter({code: :code1}).first.code).to eq(:code1)
29
+ end
30
+
31
+ it 'should filter by match filter' do
23
32
  City.create(name: 'city1')
24
33
  City.create(name: 'city2')
34
+ expect(City.filter({name: 'city'}).count).to eq(2)
25
35
  expect(City.filter({name: 'city1'}).count).to eq(1)
26
36
  expect(City.filter({name: 'city1'}).first.name).to eq('city1')
27
37
  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: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Jurado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler