Class: CursorPager::OrderValues
- Inherits:
-
Object
- Object
- CursorPager::OrderValues
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/cursor_pager/order_values.rb
Overview
OrderValue collection wrapper.
Class Method Summary collapse
-
.from_relation(relation) ⇒ Object
A relation’s order_values can either be an empty array, an array including just one string, or an array of arel ordering nodes.
Instance Method Summary collapse
- #direction ⇒ Object
-
#initialize(collection = []) ⇒ OrderValues
constructor
A new instance of OrderValues.
- #order_string ⇒ Object
Constructor Details
#initialize(collection = []) ⇒ OrderValues
Returns a new instance of OrderValues.
29 30 31 |
# File 'lib/cursor_pager/order_values.rb', line 29 def initialize(collection = []) @collection = collection end |
Class Method Details
.from_relation(relation) ⇒ Object
A relation’s order_values can either be an empty array, an array including just one string, or an array of arel ordering nodes.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cursor_pager/order_values.rb', line 15 def self.from_relation(relation) arel_order_values = relation.order_values.uniq.reject(&:blank?) collection = arel_order_values.flat_map do |value| case value when Arel::Nodes::Ordering OrderValue.from_arel_node(relation, value) when String OrderValue.from_order_string(relation, value) end end new(collection) end |
Instance Method Details
#direction ⇒ Object
33 34 35 |
# File 'lib/cursor_pager/order_values.rb', line 33 def direction @collection.first&.direction end |
#order_string ⇒ Object
37 38 39 |
# File 'lib/cursor_pager/order_values.rb', line 37 def order_string @collection.map(&:order_string).join(", ") end |