aub-record_filter 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 0
4
+ :patch: 1
@@ -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 (?)"
@@ -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 for less than' do
24
- Post.filter do
25
- with(:created_at).less_than Time.parse('2009-01-03 23:02:00')
26
- end.inspect
27
- Post.last_find.should == { :conditions => [%q{"posts".created_at < ?}, Time.parse('2009-01-03 23:02:00')] }
28
- end
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
- it 'should filter for greater than' do
31
- Post.filter do
32
- with(:created_at).greater_than Time.parse('2008-01-03 23:23:00')
33
- end.inspect
34
- Post.last_find.should == { :conditions => [%q{"posts".created_at > ?}, Time.parse('2008-01-03 23:23:00')] }
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.0
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-16 00:00:00 -07:00
13
+ date: 2009-04-17 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16