Class: Kaminari::PaginatableArray
- Inherits:
-
Array
- Object
- Array
- Kaminari::PaginatableArray
- Includes:
- ConfigurationMethods::ClassMethods
- Defined in:
- lib/kaminari/models/array_extension.rb
Overview
Kind of Array that can paginate
Instance Method Summary collapse
-
#initialize(original_array, limit_val = default_per_page, offset_val = 0) ⇒ PaginatableArray
constructor
:nodoc:.
-
#limit(num) ⇒ Object
returns another chunk of the original array.
-
#offset(num) ⇒ Object
returns another chunk of the original array.
-
#page(num = 1) ⇒ Object
items at the specified “page”.
-
#total_count ⇒ Object
total item numbers of the original array.
Methods included from ConfigurationMethods::ClassMethods
#default_per_page, #paginates_per
Constructor Details
#initialize(original_array, limit_val = default_per_page, offset_val = 0) ⇒ PaginatableArray
:nodoc:
8 9 10 11 |
# File 'lib/kaminari/models/array_extension.rb', line 8 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] || []) end |
Instance Method Details
#limit(num) ⇒ Object
returns another chunk of the original array
19 20 21 |
# File 'lib/kaminari/models/array_extension.rb', line 19 def limit(num) self.class.new @_original_array, num, offset_value end |
#offset(num) ⇒ Object
returns another chunk of the original array
29 30 31 32 33 34 35 |
# File 'lib/kaminari/models/array_extension.rb', line 29 def offset(num) arr = self.class.new @_original_array, limit_value, num class << arr include Kaminari::PageScopeMethods end arr end |
#page(num = 1) ⇒ Object
items at the specified “page”
14 15 16 |
# File 'lib/kaminari/models/array_extension.rb', line 14 def page(num = 1) offset(limit_value * ([num.to_i, 1].max - 1)) end |
#total_count ⇒ Object
total item numbers of the original array
24 25 26 |
# File 'lib/kaminari/models/array_extension.rb', line 24 def total_count @_original_array.count end |