Class: GearedPagination::Recordset
- Inherits:
-
Object
- Object
- GearedPagination::Recordset
- Defined in:
- lib/geared_pagination/recordset.rb
Instance Attribute Summary collapse
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#ratios ⇒ Object
readonly
Returns the value of attribute ratios.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(records, ordered_by: nil, per_page: nil) ⇒ Recordset
constructor
A new instance of Recordset.
- #page(param) ⇒ Object
- #page_count ⇒ Object
- #records_count ⇒ Object
Constructor Details
#initialize(records, ordered_by: nil, per_page: nil) ⇒ Recordset
Returns a new instance of Recordset.
10 11 12 13 14 |
# 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 |
Instance Attribute Details
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
8 9 10 |
# File 'lib/geared_pagination/recordset.rb', line 8 def orders @orders end |
#ratios ⇒ Object (readonly)
Returns the value of attribute ratios.
8 9 10 |
# File 'lib/geared_pagination/recordset.rb', line 8 def ratios @ratios end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
8 9 10 |
# File 'lib/geared_pagination/recordset.rb', line 8 def records @records end |
Instance Method Details
#page(param) ⇒ Object
16 17 18 |
# File 'lib/geared_pagination/recordset.rb', line 16 def page(param) Page.new portion_for(param), from: self end |
#page_count ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
34 35 36 |
# File 'lib/geared_pagination/recordset.rb', line 34 def records_count @records_count ||= records.unscope(:limit).unscope(:offset).unscope(:select).count end |