public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Refactored wp_count to pass options to wp_parse_count_options
brandonarbini (author)
Thu May 29 16:12:11 -0700 2008
mislav (committer)
Fri May 30 04:25:56 -0700 2008
commit  177b217bdc3caa0cfe2d4e41be15e1a45417ea4b
tree    212f074cf3de9063585ce50ede3d831342ee6572
parent  f8f176808f35e16c2656c13c53a186dca8c19b5a
...
122
123
124
125
126
127
128
129
130
131
132
133
134
 
 
 
135
136
137
138
139
140
141
142
143
144
...
154
155
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
158
159
...
122
123
124
 
 
 
 
 
 
 
 
 
 
125
126
127
128
129
130
131
 
 
 
132
133
134
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
0
@@ -122,23 +122,13 @@ module WillPaginate::Finders
0
     # Does the not-so-trivial job of finding out the total number of entries
0
     # in the database. It relies on the ActiveRecord +count+ method.
0
     def wp_count(options, args, finder)
0
- excludees = [:count, :order, :limit, :offset, :readonly]
0
- unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
0
- excludees << :select # only exclude the select param if it doesn't begin with DISTINCT
0
- end
0
- # count expects (almost) the same options as find
0
- count_options = options.except *excludees
0
-
0
- # merge the hash found in :count
0
- # this allows you to specify :select, :order, or anything else just for the count query
0
- count_options.update options[:count] if options[:count]
0
+ # find out if we are in a model or an association proxy
0
+ klass = (@owner and @reflection) ? @reflection.klass : self
0
+ count_options = wp_parse_count_options(options, klass)
0
 
0
       # we may have to scope ...
0
       counter = Proc.new { count(count_options) }
0
 
0
- # we may be in a model or an association proxy!
0
- klass = (@owner and @reflection) ? @reflection.klass : self
0
-
0
       count = if finder.index('find_') == 0 and klass.respond_to?(scoper = finder.sub('find', 'with'))
0
                 # scope_out adds a 'with_finder' method which acts like with_scope, if it's present
0
                 # then execute the count with the scoping provided by the with_finder
0
@@ -154,6 +144,23 @@ module WillPaginate::Finders
0
 
0
       count.respond_to?(:length) ? count.length : count
0
     end
0
+
0
+ def wp_parse_count_options(options, klass)
0
+ excludees = [:count, :order, :limit, :offset, :readonly]
0
+
0
+ unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
0
+ # only exclude the select param if it doesn't begin with DISTINCT
0
+ excludees << :select
0
+ end
0
+ # count expects (almost) the same options as find
0
+ count_options = options.except *excludees
0
+
0
+ # merge the hash found in :count
0
+ # this allows you to specify :select, :order, or anything else just for the count query
0
+ count_options.update options[:count] if options[:count]
0
+
0
+ count_options
0
+ end
0
   end
0
 end
0
 

Comments

    No one has commented yet.