birddog 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/birddog/birddog.rb +8 -4
- data/lib/birddog/field_conditions.rb +4 -4
- data/lib/birddog/version.rb +1 -1
- data/specs/birddog_spec.rb +9 -0
- metadata +18 -18
data/lib/birddog/birddog.rb
CHANGED
@@ -87,9 +87,13 @@ module Birddog
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def search(query)
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
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
|
34
|
-
conditionally_scoped(current_scope, field[:attribute], condition, cast_numeric(
|
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}"
|
data/lib/birddog/version.rb
CHANGED
data/specs/birddog_spec.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2012-03-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
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: *
|
24
|
+
version_requirements: *10364960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
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: *
|
35
|
+
version_requirements: *10364340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3-ruby
|
38
|
-
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: *
|
46
|
+
version_requirements: *10363920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
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: *
|
57
|
+
version_requirements: *10363240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: chronic
|
60
|
-
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: *
|
68
|
+
version_requirements: *10362380
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activerecord
|
71
|
-
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: *
|
79
|
+
version_requirements: *10348000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
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: *
|
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: -
|
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: -
|
141
|
+
hash: -4028923489446970786
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project: birddog
|
144
144
|
rubygems_version: 1.8.10
|