class GearedPagination::Recordset
Attributes
orders[R]
ratios[R]
records[R]
Public Class Methods
new(records, ordered_by: nil, per_page: nil)
click to toggle source
# File lib/geared_pagination/recordset.rb, line 10 def initialize(records, ordered_by: nil, per_page: nil) @records = records @orders = Order.wrap_many(ordered_by) @ratios = Ratios.new(per_page) end
Public Instance Methods
page(param)
click to toggle source
# File lib/geared_pagination/recordset.rb, line 16 def page(param) Page.new portion_for(param), from: self end
page_count()
click to toggle source
# File lib/geared_pagination/recordset.rb, line 20 def page_count @page_count ||= begin count = 0 residual = records_count while residual > 0 count += 1 residual = residual - ratios[count] end count > 0 ? count : 1 end end
records_count()
click to toggle source
# File lib/geared_pagination/recordset.rb, line 34 def records_count @records_count ||= records.unscope(:limit).unscope(:offset).count end
Private Instance Methods
cursor_from(param)
click to toggle source
# File lib/geared_pagination/recordset.rb, line 51 def cursor_from(param) Cursor.from_param(param) end
page_number_from(param)
click to toggle source
# File lib/geared_pagination/recordset.rb, line 47 def page_number_from(param) param.to_i > 0 ? param.to_i : 1 end
portion_for(param)
click to toggle source
# File lib/geared_pagination/recordset.rb, line 39 def portion_for(param) if orders.none? PortionAtOffset.new page_number: page_number_from(param), per_page: ratios else PortionAtCursor.new cursor: cursor_from(param), ordered_by: orders, per_page: ratios end end