mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
be paginatable if both limit and offset are given when initializing
don't have to call offset() to be paginatable
This commit is contained in:
parent
b5e16c0a94
commit
6629f5bfe0
2 changed files with 12 additions and 5 deletions
|
@ -12,6 +12,12 @@ module Kaminari
|
|||
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]
|
||||
|
||||
if options[:limit] && options[:offset]
|
||||
class << self
|
||||
include Kaminari::PageScopeMethods
|
||||
end
|
||||
end
|
||||
|
||||
if options[:total_count]
|
||||
super original_array
|
||||
else
|
||||
|
@ -36,11 +42,7 @@ module Kaminari
|
|||
|
||||
# returns another chunk of the original array
|
||||
def offset(num)
|
||||
arr = self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count
|
||||
class << arr
|
||||
include Kaminari::PageScopeMethods
|
||||
end
|
||||
arr
|
||||
self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Kaminari::PaginatableArray do
|
||||
context 'specifying limit and offset when initializing' do
|
||||
subject { Kaminari::PaginatableArray.new((1..100).to_a, :limit => 10, :offset => 20) }
|
||||
its(:current_page) { should == 3 }
|
||||
end
|
||||
|
||||
let(:array) { Kaminari::PaginatableArray.new((1..100).to_a) }
|
||||
describe '#page' do
|
||||
shared_examples_for 'the first page of array' do
|
||||
|
|
Loading…
Reference in a new issue