aub-record_filter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/record_filter/dsl/restriction.rb +6 -1
- data/lib/record_filter/restrictions.rb +12 -0
- data/spec/restrictions_spec.rb +12 -11
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -8,13 +8,18 @@ module RecordFilter
|
|
8
8
|
@column, @negated, @operator = column, negated, nil
|
9
9
|
end
|
10
10
|
|
11
|
-
[:equal_to, :is_null, :less_than, :greater_than, :in, :between].each do |operator|
|
11
|
+
[:equal_to, :is_null, :less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to, :in, :between].each do |operator|
|
12
12
|
define_method(operator) do |*args|
|
13
13
|
@value = args[0]
|
14
14
|
@operator = operator
|
15
15
|
self
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
alias_method :gt, :greater_than
|
20
|
+
alias_method :gte, :greater_than_or_equal_to
|
21
|
+
alias_method :lt, :less_than
|
22
|
+
alias_method :lte, :less_than_or_equal_to
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -44,12 +44,24 @@ module RecordFilter
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
class LessThanOrEqualTo < Base
|
48
|
+
def to_positive_sql
|
49
|
+
"#{@column_name} <= ?"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
47
53
|
class GreaterThan < Base
|
48
54
|
def to_positive_sql
|
49
55
|
"#{@column_name} > ?"
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
59
|
+
class GreaterThanOrEqualTo < Base
|
60
|
+
def to_positive_sql
|
61
|
+
"#{@column_name} >= ?"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
class In < Base
|
54
66
|
def to_positive_sql
|
55
67
|
"#{@column_name} IN (?)"
|
data/spec/restrictions_spec.rb
CHANGED
@@ -20,18 +20,19 @@ describe 'RecordFilter restrictions' do
|
|
20
20
|
Post.last_find.should == { :conditions => [%q{("posts".permalink = ?) AND ("posts".blog_id = ?)}, 'blog-post', 3] }
|
21
21
|
end
|
22
22
|
|
23
|
-
it 'should filter
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
it 'should filter by comparison operators' do
|
24
|
+
[[:greater_than, :gt, '>'], [:less_than, :lt, '<'],
|
25
|
+
[:less_than_or_equal_to, :lte, '<='], [:greater_than_or_equal_to, :gte, '>=']].each do |set|
|
26
|
+
Post.filter do
|
27
|
+
with(:created_at).send(set[0], Time.parse('2009-01-03 23:02:00'))
|
28
|
+
end.inspect
|
29
|
+
Post.last_find.should == { :conditions => ["\"posts\".created_at #{set[2]} ?", Time.parse('2009-01-03 23:02:00')] }
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
Post.filter do
|
32
|
+
with(:created_at).send(set[1], Time.parse('2009-01-03 23:02:00'))
|
33
|
+
end.inspect
|
34
|
+
Post.last_find.should == { :conditions => ["\"posts\".created_at #{set[2]} ?", Time.parse('2009-01-03 23:02:00')] }
|
35
|
+
end
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'should filter for in' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aub-record_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-04-
|
13
|
+
date: 2009-04-17 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|