mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
add current_page to PaginatableArray
This commit is contained in:
parent
beeb13bbde
commit
7532ecc4fc
2 changed files with 6 additions and 2 deletions
|
@ -4,14 +4,16 @@ module Kaminari
|
|||
include Kaminari::ConfigurationMethods::ClassMethods
|
||||
|
||||
attr_internal_accessor :limit_value, :offset_value
|
||||
attr_internal_reader :current_page
|
||||
|
||||
def initialize(original_array, limit_val = default_per_page, offset_val = 0) #:nodoc:
|
||||
@_original_array, @_limit_value, @_offset_value = original_array, limit_val, offset_val
|
||||
super(original_array[offset_val, limit_val] || [])
|
||||
@_original_array, @_limit_value, @_offset_value, @_current_page = original_array, limit_val.to_i, offset_val.to_i, nil
|
||||
super(original_array[offset_value, limit_value] || [])
|
||||
end
|
||||
|
||||
# items at the specified "page"
|
||||
def page(num = 1)
|
||||
@_current_page = num
|
||||
offset(limit_value * ([num.to_i, 1].max - 1))
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ describe Kaminari::PaginatableArray do
|
|||
describe '#page' do
|
||||
shared_examples_for 'the first page of array' do
|
||||
it { should have(25).users }
|
||||
its(:current_page) { should == 1 }
|
||||
its(:first) { should == 1 }
|
||||
end
|
||||
|
||||
|
@ -20,6 +21,7 @@ describe Kaminari::PaginatableArray do
|
|||
context 'page 2' do
|
||||
subject { array.page 2 }
|
||||
it { should have(25).users }
|
||||
its(:current_page) { should == 2 }
|
||||
its(:first) { should == 26 }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue