Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move Active Record pagination outside of the "Finders" namespace

commit dfd206bf21957d7c25a7fdde7ff2ecfa3c9e4804 1 parent fb36491
@mislav authored
View
26 lib/will_paginate/finders/active_record.rb → lib/will_paginate/active_record.rb
@@ -1,7 +1,8 @@
-require 'will_paginate/finders/base'
+require 'will_paginate/per_page'
+require 'will_paginate/collection'
require 'active_record'
-module WillPaginate::Finders
+module WillPaginate
# = Paginating finders for ActiveRecord models
#
# WillPaginate adds +paginate+, +per_page+ and other methods to
@@ -15,8 +16,8 @@ module WillPaginate::Finders
#
module ActiveRecord
# In Rails, this is automatically called to mix-in pagination functionality to ActiveRecord.
- def self.enable!
- ::ActiveRecord::Base.extend Base
+ def self.setup
+ ::ActiveRecord::Base.extend PerPage
::ActiveRecord::Base.extend ActiveRecord::Pagination
::ActiveRecord::Base.extend ActiveRecord::BaseMethods
@@ -106,9 +107,14 @@ def to_a
module Pagination
def paginate(options)
- pagenum, per_page, total = wp_parse_options(options)
- count_options = options[:count]
- options = options.except(:page, :per_page, :total_entries, :count)
+ options = options.dup
+ pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
+ per_page = options.delete(:per_page) || self.per_page
+ total = options.delete(:total_entries)
+
+ count_options = options.delete(:count)
+ options.delete(:page)
+
rel = limit(per_page).page(pagenum)
rel = rel.apply_finder_options(options) if options.any?
rel.wp_count_options = count_options if count_options
@@ -142,7 +148,11 @@ module BaseMethods
# application.
#
def paginate_by_sql(sql, options)
- WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
+ pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
+ per_page = options[:per_page] || self.per_page
+ total = options[:total_entries]
+
+ WillPaginate::Collection.create(pagenum, per_page, total) do |pager|
query = sanitize_sql(sql.dup)
original_query = query.dup
# add limit, offset
View
4 lib/will_paginate/railtie.rb
@@ -5,8 +5,8 @@ module WillPaginate
class Railtie < Rails::Railtie
initializer "will_paginate" do |app|
ActiveSupport.on_load :active_record do
- require 'will_paginate/finders/active_record'
- WillPaginate::Finders::ActiveRecord.enable!
+ require 'will_paginate/active_record'
+ WillPaginate::ActiveRecord.setup
end
ActiveSupport.on_load :action_controller do
View
6 spec/finders/active_record_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
-require 'will_paginate/finders/active_record'
+require 'will_paginate/active_record'
require File.expand_path('../activerecord_test_connector', __FILE__)
ActiverecordTestConnector.setup
-WillPaginate::Finders::ActiveRecord.enable!
+WillPaginate::ActiveRecord.setup
-describe WillPaginate::Finders::ActiveRecord do
+describe WillPaginate::ActiveRecord do
extend ActiverecordTestConnector::FixtureSetup
Please sign in to comment.
Something went wrong with that request. Please try again.