Class: ActiveRecord::SearchService::Order
- Inherits:
-
Object
- Object
- ActiveRecord::SearchService::Order
- Defined in:
- app/services/active_record/search_service.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#order_str ⇒ Object
readonly
Returns the value of attribute order_str.
Instance Method Summary collapse
- #apply(relation) ⇒ Object
-
#initialize(attribute, direction, order_str) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(attribute, direction, order_str) ⇒ Order
Returns a new instance of Order.
65 66 67 68 69 |
# File 'app/services/active_record/search_service.rb', line 65 def initialize(attribute, direction, order_str) @attribute = attribute @direction = direction @order_str = order_str end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
63 64 65 |
# File 'app/services/active_record/search_service.rb', line 63 def attribute @attribute end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
63 64 65 |
# File 'app/services/active_record/search_service.rb', line 63 def direction @direction end |
#order_str ⇒ Object (readonly)
Returns the value of attribute order_str.
63 64 65 |
# File 'app/services/active_record/search_service.rb', line 63 def order_str @order_str end |
Instance Method Details
#apply(relation) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/services/active_record/search_service.rb', line 71 def apply(relation) if order_str.present? relation.order(order_str) elsif attribute.present? relation.order(attribute => direction) else relation end end |