Class: GearedPagination::PortionAtCursor
- Inherits:
-
Object
- Object
- GearedPagination::PortionAtCursor
- Defined in:
- lib/geared_pagination/portions/portion_at_cursor.rb
Defined Under Namespace
Classes: Equal, Inequal, Match, Predicate, Selection
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#ratios ⇒ Object
readonly
Returns the value of attribute ratios.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #from(scope) ⇒ Object
-
#initialize(cursor: Cursor.new, ordered_by:, per_page: Ratios.new) ⇒ PortionAtCursor
constructor
A new instance of PortionAtCursor.
- #next_param(scope) ⇒ Object
Constructor Details
#initialize(cursor: Cursor.new, ordered_by:, per_page: Ratios.new) ⇒ PortionAtCursor
Returns a new instance of PortionAtCursor.
10 11 12 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 10 def initialize(cursor: Cursor.new, ordered_by:, per_page: Ratios.new) @cursor, @orders, @ratios = cursor, ordered_by, per_page end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
7 8 9 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 7 def cursor @cursor end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
7 8 9 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 7 def orders @orders end |
#ratios ⇒ Object (readonly)
Returns the value of attribute ratios.
7 8 9 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 7 def ratios @ratios end |
Instance Method Details
#cache_key ⇒ Object
27 28 29 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 27 def cache_key "#{page_number}:#{ratios.cache_key}" end |
#from(scope) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/geared_pagination/portions/portion_at_cursor.rb', line 14 def from(scope) if scope.order_values.none? && scope.limit_value.nil? selection_from(scope).order(orderings).limit(limit) else raise ArgumentError, "Can't paginate relation with ORDER BY or LIMIT clauses (got #{scope.to_sql})" end end |