Class: Uchi::SortOrder
- Inherits:
-
Object
- Object
- Uchi::SortOrder
- Defined in:
- lib/uchi/sort_order.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(query) ⇒ Object
- #ascending? ⇒ Boolean
- #descending? ⇒ Boolean
-
#initialize(name, direction) ⇒ SortOrder
constructor
A new instance of SortOrder.
Constructor Details
#initialize(name, direction) ⇒ SortOrder
Returns a new instance of SortOrder.
30 31 32 33 |
# File 'lib/uchi/sort_order.rb', line 30 def initialize(name, direction) @name = name.to_sym @direction = direction.to_sym end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
3 4 5 |
# File 'lib/uchi/sort_order.rb', line 3 def direction @direction end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/uchi/sort_order.rb', line 3 def name @name end |
Class Method Details
.from_params(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/uchi/sort_order.rb', line 6 def from_params(params) sort_params = params[:sort] || {} return nil if sort_params.empty? by = sort_params[:by] return by unless by direction = sort_params[:direction] || :asc new(by, direction) end |
Instance Method Details
#apply(query) ⇒ Object
22 23 24 |
# File 'lib/uchi/sort_order.rb', line 22 def apply(query) query.order(name => direction) end |
#ascending? ⇒ Boolean
18 19 20 |
# File 'lib/uchi/sort_order.rb', line 18 def ascending? direction == :asc end |
#descending? ⇒ Boolean
26 27 28 |
# File 'lib/uchi/sort_order.rb', line 26 def descending? direction == :desc end |