birddog 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -188,7 +188,7 @@ module Birddog
188
188
 
189
189
  case field[:type]
190
190
  when :string then
191
- conditions_for_string_search(current_scope, field, value)
191
+ conditions_for_string_search(current_scope, field, condition, value)
192
192
  when :float, :decimal, :integer then
193
193
  conditions_for_numeric(current_scope, field, condition, value, field[:type])
194
194
  when :date, :datetime, :time then
@@ -2,19 +2,25 @@ module Birddog
2
2
 
3
3
  module FieldConditions
4
4
 
5
- def conditions_for_string_search(current_scope, field, value)
6
- search_con = "=~"
7
- value_to_search = value.dup
5
+ def conditions_for_string_search(current_scope, field, condition, value)
6
+ search_con = condition
7
+ strict_equality = (search_con == "==")
8
+ value_to_search = (value ? value.dup : nil)
8
9
 
9
- if field[:match_substring]
10
- value_to_search = "%#{value_to_search}%"
11
- end
10
+ if !strict_equality
11
+ if field[:match_substring]
12
+ search_con = "=~"
13
+ value_to_search = "%#{value_to_search}%"
14
+ end
12
15
 
13
- if field[:regex] && regexed?(value)
14
- # TODO check db driver to determine regex operator for DB (current is Postgres)
15
- value_to_search = value[1..value.size-2]
16
- elsif field[:wildcard] && value_to_search.include?("*")
17
- value_to_search.gsub!(/[\*]/, "%")
16
+ if field[:regex] && regexed?(value)
17
+ # TODO check db driver to determine regex operator for DB (current is Postgres)
18
+ search_con = "=~"
19
+ value_to_search = value[1..value.size-2]
20
+ elsif field[:wildcard] && value_to_search.include?("*")
21
+ search_con = "=~"
22
+ value_to_search.gsub!(/[\*]/, "%")
23
+ end
18
24
  end
19
25
 
20
26
  conditionally_scoped(current_scope, field[:attribute], search_con, value_to_search, field[:aggregate])
@@ -54,7 +60,7 @@ module Birddog
54
60
  current_scope.__send__(having_or_where, field.lteq(value))
55
61
  when :>=, ">=", "=>" then
56
62
  current_scope.__send__(having_or_where, field.gteq(value))
57
- when "=" then
63
+ when "=", "==" then
58
64
  current_scope.__send__(having_or_where, field.eq(value))
59
65
  else
60
66
  raise "#{condition} not defined for #{field}"
@@ -1,3 +1,3 @@
1
1
  module Birddog
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -36,11 +36,6 @@ describe Birddog::Birddog do ####################
36
36
  User.scopes_for_query("last_name:Doe").size.must_equal(1)
37
37
  end
38
38
 
39
- it "can find using case insensitive search" do
40
- User.scopes_for_query("insensitive_last_name:doe").must_include(@john)
41
- User.scopes_for_query("insensitive_last_name:doe").size.must_equal(1)
42
- end
43
-
44
39
  it "can find matching substrings" do
45
40
  User.scopes_for_query("substringed_last_name:oe").must_include(@john)
46
41
  User.scopes_for_query("substringed_last_name:oe").size.must_equal(1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birddog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-04 00:00:00.000000000Z
12
+ date: 2012-03-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &11416560 !ruby/object:Gem::Requirement
16
+ requirement: &17950520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11416560
24
+ version_requirements: *17950520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &11415800 !ruby/object:Gem::Requirement
27
+ requirement: &17949040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11415800
35
+ version_requirements: *17949040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3-ruby
38
- requirement: &11415160 !ruby/object:Gem::Requirement
38
+ requirement: &17944840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *11415160
46
+ version_requirements: *17944840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &11414280 !ruby/object:Gem::Requirement
49
+ requirement: &17944240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11414280
57
+ version_requirements: *17944240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: chronic
60
- requirement: &11413760 !ruby/object:Gem::Requirement
60
+ requirement: &17943700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *11413760
68
+ version_requirements: *17943700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
- requirement: &11413240 !ruby/object:Gem::Requirement
71
+ requirement: &17943220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *11413240
79
+ version_requirements: *17943220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &11399120 !ruby/object:Gem::Requirement
82
+ requirement: &17942740 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *11399120
90
+ version_requirements: *17942740
91
91
  description: Seeeeeeeee Readme
92
92
  email:
93
93
  - brandonsdewitt@gmail.com
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: 789401553101841617
132
+ hash: -3010040565782665545
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: 789401553101841617
141
+ hash: -3010040565782665545
142
142
  requirements: []
143
143
  rubyforge_project: birddog
144
144
  rubygems_version: 1.8.10