1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

API change for PaginatableArray.new

using options hash instead of three nullable arguments
This commit is contained in:
Akira Matsuda 2011-08-24 20:16:14 +09:00
parent 807a2fa3e7
commit 4d50416cdd

View file

@ -5,9 +5,13 @@ module Kaminari
attr_internal_accessor :limit_value, :offset_value attr_internal_accessor :limit_value, :offset_value
def initialize(original_array, limit_val = default_per_page, offset_val = 0, count = nil) #:nodoc: # ==== Options
@_original_array, @_limit_value, @_offset_value, @_total_count = original_array, limit_val.to_i, offset_val.to_i, count # * <tt>:limit</tt> - limit
super(original_array[offset_val, limit_val] || []) # * <tt>:offset</tt> - offset
# * <tt>:total_count</tt> - total_count
def initialize(original_array, options = {})
@_original_array, @_limit_value, @_offset_value, @_total_count = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count]
super(original_array[@_offset_value, @_limit_value] || [])
end end
# items at the specified "page" # items at the specified "page"
@ -17,7 +21,7 @@ module Kaminari
# returns another chunk of the original array # returns another chunk of the original array
def limit(num) def limit(num)
self.class.new @_original_array, num, offset_value self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count
end end
# total item numbers of the original array # total item numbers of the original array
@ -27,7 +31,7 @@ module Kaminari
# returns another chunk of the original array # returns another chunk of the original array
def offset(num) def offset(num)
arr = self.class.new @_original_array, limit_value, num, total_count arr = self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count
class << arr class << arr
include Kaminari::PageScopeMethods include Kaminari::PageScopeMethods
end end