aub-record_filter 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = record_filter
2
2
 
3
- record_filter is a DSL for specifying criteria for ActiveRecord queries in pure Ruby.
3
+ record_filter is a DSL for specifying ActiveRecord queries in pure Ruby.
4
4
  It has support for filters created on the fly and for named filters that are associated with object types.
5
5
  record_filter has the following top-level features:
6
6
 
@@ -10,9 +10,14 @@ record_filter has the following top-level features:
10
10
  * Allows chaining of filters with each other and with named scopes to create complex queries.
11
11
  * Takes advantage of the associations in your ActiveRecord objects for a clean implicit join API.
12
12
 
13
+ == Documentation
14
+
15
+ The complete RDoc documentation is available at http://aub.github.com/record_filter/rdoc/. This page is
16
+ intended to be a getting started guide that should cover the most common uses.
17
+
13
18
  == Installation
14
19
 
15
- gem install outoftime-record_filter --source=http://gems.github.com
20
+ gem install aub-record_filter --source=http://gems.github.com
16
21
 
17
22
  == Using Filters
18
23
 
@@ -31,7 +36,7 @@ This could be expressed in ActiveRecord as:
31
36
  :joins => :posts,
32
37
  :conditions => ['posts.permalink IS NULL AND blogs.created_at > ?', 'blog-post', 1.day.ago)
33
38
 
34
- and it returns the same result, a list of Blog objects that are returned from the query. This
39
+ and it returns the same result, a list of Blog objects that are the result of the query. This
35
40
  type of filter is designed to be created on the fly, but if you have a filter that you would like
36
41
  to use in more than one place, it can be added to a class as a named filter. The following example
37
42
  creates the same filter as above and executes it:
@@ -51,7 +56,7 @@ complex query:
51
56
 
52
57
  class Post < ActiveRecord::Base
53
58
  named_filter(:title_is_monkeys) { with(:title, 'monkeys') }
54
- named_filter(:permalink_is_donkeys) { with(:title, 'donkeys') }
59
+ named_filter(:permalink_is_donkeys) { with(:permalink, 'donkeys') }
55
60
  end
56
61
 
57
62
  Post.title_is_monkeys.permalink_is_donkeys
@@ -89,7 +94,7 @@ model even if called from a join.
89
94
 
90
95
  == Specifying Filters
91
96
 
92
- record_filter supports all of SQL query abstractions provided by ActiveRecord, specifically:
97
+ record_filter supports all of the SQL query abstractions provided by ActiveRecord, specifically:
93
98
 
94
99
  * Conditions
95
100
  * Boolean operations
@@ -141,7 +146,7 @@ The following condition types are supported through the Restriction API:
141
146
 
142
147
  Conditions can be combined with boolean operators using the methods all_of, any_of, none_of
143
148
  and not_all_of. These methods take a block where any conditions they contain will be combined
144
- using AND, OR and NOT to create the correct condition. The block can also contain any number of
149
+ using AND, OR and NOT to create the correct clause. The block can also contain any number of
145
150
  joins or other boolean operations. The default operator is all_of.
146
151
 
147
152
  Post.filter do
@@ -198,6 +203,7 @@ added. Explicit joins also allow conditions to be set on columns of the table be
198
203
  join(Comment, :inner) do
199
204
  on(:id => :commentable_id)
200
205
  on(:commentable_type).equal_to('Post')
206
+ with(:created_at).less_than(1.year.ago)
201
207
  end
202
208
 
203
209
  With implicit joins, it is also possible to use a hash as the association name, in which case
@@ -249,7 +255,7 @@ order in which they were given.
249
255
 
250
256
  (The MIT License)
251
257
 
252
- Copyright (c) 2008 Mat Brown, Aubrey Holland
258
+ Copyright (c) 2008 Aubrey Holland, Mat Brown
253
259
 
254
260
  Permission is hereby granted, free of charge, to any person obtaining
255
261
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -13,10 +13,10 @@ begin
13
13
  Jeweler::Tasks.new do |gemspec|
14
14
  gemspec.name = 'record_filter'
15
15
  gemspec.summary = 'Pure-ruby criteria API for building complex queries in ActiveRecord'
16
- gemspec.email = 'mat@patch.com'
17
- gemspec.homepage = 'http://github.com/outoftime/record_filter/tree/master'
16
+ gemspec.email = 'aubreyholland@gmail.com'
17
+ gemspec.homepage = 'http://github.com/aub/record_filter/tree/master'
18
18
  gemspec.description = 'Pure-ruby criteria API for building complex queries in ActiveRecord'
19
- gemspec.authors = ['Mat Brown', 'Aubrey Holland']
19
+ gemspec.authors = ['Aubrey Holland', 'Mat Brown']
20
20
  end
21
21
  rescue LoadError
22
22
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 9
4
- :patch: 0
4
+ :patch: 1
@@ -94,13 +94,15 @@ module RecordFilter
94
94
  # column<Symbol, Hash>::
95
95
  # If a symbol is specified, it is taken to represent the name of a column on the
96
96
  # class being filtered. If a hash is given, it should represent a path through the
97
- # joins to a column in one of the joined tables.
97
+ # joins to a column in one of the joined tables. If a string is given, it is used
98
+ # without modification as the grouping parameter.
98
99
  #
99
100
  # ==== Returns
100
101
  # nil
101
102
  #
102
103
  # ==== Alternatives
103
- # As described above, it is possible to pass either a symbol or a hash as the argument.
104
+ # As described above, it is possible to pass either a symbol, a hash, or a string
105
+ # as the argument.
104
106
  #
105
107
  # @public
106
108
  def group_by(column)
@@ -13,11 +13,11 @@ module RecordFilter
13
13
  column = column.values[0]
14
14
  end
15
15
 
16
- if (!table.has_column(column))
17
- raise ColumnNotFoundException.new("The column #{column} was not found in #{table.table_name}.")
16
+ if (table.has_column(column))
17
+ "#{table.table_alias}.#{column}"
18
+ else
19
+ column
18
20
  end
19
-
20
- "#{table.table_alias}.#{column}"
21
21
  end
22
22
  end
23
23
  end
@@ -42,12 +42,12 @@ describe 'raising exceptions' do
42
42
  }.should raise_error(RecordFilter::ColumnNotFoundException)
43
43
  end
44
44
 
45
- it 'should get ColumnNotFoundException for group_by' do
45
+ it 'should not get ColumnNotFoundException for group_by' do
46
46
  lambda {
47
47
  Post.filter do
48
48
  group_by(:this_is_not_there)
49
49
  end.inspect
50
- }.should raise_error(RecordFilter::ColumnNotFoundException)
50
+ }.should_not raise_error(RecordFilter::ColumnNotFoundException)
51
51
  end
52
52
 
53
53
  it 'should get AssociationNotFoundException for orders on bad associations' do
@@ -145,5 +145,12 @@ describe 'filter qualifiers' do
145
145
  end.inspect
146
146
  Post.last_find[:group].should == %q("posts".created_at, posts__photo.format)
147
147
  end
148
+
149
+ it 'should accept random strings as the column name' do
150
+ Post.filter do
151
+ group_by("abcdef")
152
+ end.find(:all, :select => 'posts.id as abcdef').inspect
153
+ Post.last_find[:group].should == 'abcdef'
154
+ end
148
155
  end
149
156
  end
data/spec/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aub-record_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
- - Mat Brown
8
7
  - Aubrey Holland
8
+ - Mat Brown
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -15,7 +15,7 @@ default_executable:
15
15
  dependencies: []
16
16
 
17
17
  description: Pure-ruby criteria API for building complex queries in ActiveRecord
18
- email: mat@patch.com
18
+ email: aubreyholland@gmail.com
19
19
  executables: []
20
20
 
21
21
  extensions: []
@@ -65,7 +65,7 @@ files:
65
65
  - test/performance_test.rb
66
66
  - test/test.db
67
67
  has_rdoc: true
68
- homepage: http://github.com/outoftime/record_filter/tree/master
68
+ homepage: http://github.com/aub/record_filter/tree/master
69
69
  post_install_message:
70
70
  rdoc_options:
71
71
  - --charset=UTF-8