birddog 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,9 +87,13 @@ module Birddog
87
87
  end
88
88
 
89
89
  def search(query)
90
- key, value = tokenize(query)
91
- key, value = "text_search", key if value.nil?
92
- scope_for(@model, key, value)
90
+ if query.include?("..") && query =~ /\s*([[:alnum:]_]+)\s*:\s*{([^[:space:]]+)}\.\.{([^[:space:]]+)}\s*$/ # query is a range object
91
+ begin_range = @model.scopes_for_query("#{$1}:>=#{$2}")
92
+ return begin_range.scopes_for_query("#{$1}:<=#{$3}")
93
+ else
94
+ key, value = tokenize(query)
95
+ return scope_for(@model, key, value)
96
+ end
93
97
  end
94
98
 
95
99
  ################## PRIVATES ####################
@@ -190,7 +194,7 @@ module Birddog
190
194
  when :string then
191
195
  conditions_for_string_search(current_scope, field, condition, value)
192
196
  when :float, :decimal, :integer then
193
- conditions_for_numeric(current_scope, field, condition, value, field[:type])
197
+ conditions_for_numeric(current_scope, field, condition, value)
194
198
  when :date, :datetime, :time then
195
199
  conditions_for_date(current_scope, field, condition, value)
196
200
  else
@@ -30,8 +30,8 @@ module Birddog
30
30
  conditionally_scoped(current_scope, field[:attribute], condition, value.value.strftime("%Y-%m-%d"), field[:aggregate])
31
31
  end
32
32
 
33
- def conditions_for_numeric(current_scope, field, condition, value, field_type)
34
- conditionally_scoped(current_scope, field[:attribute], condition, cast_numeric(field_type, value), field[:aggregate], true)
33
+ def conditions_for_numeric(current_scope, field, condition, value)
34
+ conditionally_scoped(current_scope, field[:attribute], condition, cast_numeric(field[:type], value), field[:aggregate], true)
35
35
  end
36
36
 
37
37
  def cast_numeric(field_type, value)
@@ -46,7 +46,7 @@ module Birddog
46
46
  def conditionally_scoped(current_scope, field, condition, value, aggregate, is_numeric = false)
47
47
  having_or_where = (aggregate ? :having : :where)
48
48
  scope = case condition
49
- when "=~", "~=" then
49
+ when :=~, "=~", "~=" then
50
50
  if is_numeric
51
51
  current_scope.__send__(having_or_where, field.gteq(value.floor).and(field.lt((value + 1).floor)))
52
52
  else
@@ -60,7 +60,7 @@ module Birddog
60
60
  current_scope.__send__(having_or_where, field.lteq(value))
61
61
  when :>=, ">=", "=>" then
62
62
  current_scope.__send__(having_or_where, field.gteq(value))
63
- when "=", "==" then
63
+ when :==, "=", "==" then
64
64
  current_scope.__send__(having_or_where, field.eq(value))
65
65
  else
66
66
  raise "#{condition} not defined for #{field}"
@@ -1,3 +1,3 @@
1
1
  module Birddog
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,6 +10,15 @@ describe Birddog::Birddog do ####################
10
10
  @tv = @john.products.create(:name => "TV", :value => 200)
11
11
  end
12
12
 
13
+ describe "ranges" do
14
+ it "allows ranges on decimals" do
15
+ results = Product.scopes_for_query("value:{10}..{300}")
16
+ results.must_include(@ducky)
17
+ results.must_include(@apple_duck)
18
+ results.must_include(@tv)
19
+ end
20
+ end
21
+
13
22
  it "finds a user by first_name" do
14
23
  User.scopes_for_query("first_name:John").must_include(@john)
15
24
  end
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.1.0
4
+ version: 0.1.1
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-05 00:00:00.000000000Z
12
+ date: 2012-03-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &17950520 !ruby/object:Gem::Requirement
16
+ requirement: &10364960 !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: *17950520
24
+ version_requirements: *10364960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &17949040 !ruby/object:Gem::Requirement
27
+ requirement: &10364340 !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: *17949040
35
+ version_requirements: *10364340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3-ruby
38
- requirement: &17944840 !ruby/object:Gem::Requirement
38
+ requirement: &10363920 !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: *17944840
46
+ version_requirements: *10363920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &17944240 !ruby/object:Gem::Requirement
49
+ requirement: &10363240 !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: *17944240
57
+ version_requirements: *10363240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: chronic
60
- requirement: &17943700 !ruby/object:Gem::Requirement
60
+ requirement: &10362380 !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: *17943700
68
+ version_requirements: *10362380
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
- requirement: &17943220 !ruby/object:Gem::Requirement
71
+ requirement: &10348000 !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: *17943220
79
+ version_requirements: *10348000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &17942740 !ruby/object:Gem::Requirement
82
+ requirement: &10347500 !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: *17942740
90
+ version_requirements: *10347500
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: -3010040565782665545
132
+ hash: -4028923489446970786
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: -3010040565782665545
141
+ hash: -4028923489446970786
142
142
  requirements: []
143
143
  rubyforge_project: birddog
144
144
  rubygems_version: 1.8.10