0
@@ -55,9 +55,8 @@ module WillPaginate
0
def paginate(*args, &block)
0
- options = options.dup unless !options or options.key? :finder
0
- page, per_page, total_entries = wp_parse_options!(options)
0
- finder = options.delete(:finder) || 'find'
0
+ page, per_page, total_entries = wp_parse_options(options)
0
+ finder = (options[:finder] || 'find').to_s
0
# an array of IDs may have been given:
0
@@ -67,13 +66,15 @@ module WillPaginate
0
WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
0
- args << options.except(:count).merge(:offset => pager.offset, :limit => pager.per_page)
0
+ count_options = options.except :page, :per_page, :total_entries, :finder
0
+ find_options = count_options.except(:count).update(:offset => pager.offset, :limit => pager.per_page)
0
- @options_from_last_find = nil
0
+ # @options_from_last_find = nil
0
pager.replace send(finder, *args, &block)
0
# magic counting for user convenience:
0
- pager.total_entries = wp_count
!(options, args, finder) unless pager.total_entries
0
+ pager.total_entries = wp_count
(count_options, args, finder) unless pager.total_entries
0
@@ -91,12 +92,11 @@ module WillPaginate
0
def paginate_by_sql(sql, options)
0
- WillPaginate::Collection.create(*wp_parse_options
!(options)) do |pager|
0
+ WillPaginate::Collection.create(*wp_parse_options
(options)) do |pager|
0
query = sanitize_sql(sql)
0
- options.update :offset => pager.offset, :limit => pager.per_page
0
original_query = query.dup
0
- add_limit! query, options
0
+ add_limit! query, :offset => pager.offset, :limit => pager.per_page
0
pager.replace find_by_sql(query)
0
@@ -131,7 +131,7 @@ module WillPaginate
0
finder.sub!('find', 'find_all') if finder.index('find_by_') == 0
0
- raise ArgumentError, '
hash parameters expected' unless options.respond_to? :symbolize_keys!0
+ raise ArgumentError, '
parameter hash expected' unless options.respond_to? :symbolize_keys0
options[:finder] = finder
0
@@ -139,7 +139,7 @@ module WillPaginate
0
paginate(*args, &block)
0
- def wp_count
!(options, args, finder)
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
@@ -149,7 +149,7 @@ module WillPaginate
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.delete(:count) || {}) if options.key? :count0
+ count_options.update
options[:count] if options[:count]0
# we may have to scope ...
0
counter = Proc.new { count(count_options) }
0
@@ -173,18 +173,18 @@ module WillPaginate
0
count.respond_to?(:length) ? count.length : count
0
- def wp_parse_options!(options)
0
- raise ArgumentError, 'hash parameters expected' unless options.respond_to? :symbolize_keys!
0
- options.symbolize_keys!
0
+ def wp_parse_options(options)
0
+ raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys
0
+ options = options.symbolize_keys
0
raise ArgumentError, ':page parameter required' unless options.key? :page
0
if options[:count] and options[:total_entries]
0
- raise ArgumentError, ':count and :total_entries are mutually exclusive
parameters'
0
+ raise ArgumentError, ':count and :total_entries are mutually exclusive
'
0
- page = options.delete(:page) || 1
0
- per_page = options.delete(:per_page) || self.per_page
0
- total = options.delete(:total_entries)
0
+ page = options[:page] || 1
0
+ per_page = options[:per_page] || self.per_page
0
+ total = options[:total_entries]
0
[page, per_page, total]
Comments
No one has commented yet.