lib/paginate/base.rb in paginate-2.0.0 vs lib/paginate/base.rb in paginate-3.0.0

- old
+ new

@@ -1,14 +1,17 @@ module Paginate class Base attr_accessor :options + attr_accessor :scope - def initialize(options = {}) + def initialize(scope, options = {}) + @scope = scope + if options.kind_of?(Hash) @options = options else - @options = {:page => options.to_i} + @options = {page: options.to_i} end @options.reverse_merge!(Paginate::Config.to_hash) end @@ -19,11 +22,11 @@ def next_page? collection_size > options[:size] end def previous_page? - options[:page] > 1 + page > 1 end def page [1, options.fetch(:page, 1).to_i].max end @@ -35,9 +38,15 @@ def limit [options[:size], 10].compact.first.to_i + 1 end def to_options - { :limit => limit, :offset => offset } + {limit: limit, offset: offset} + end + + def to_scope + scope + .limit(limit) + .offset(offset) end end end