Class: Jsonapi::QueryBuilder::Mixins::Sort::Param
- Inherits:
-
Object
- Object
- Jsonapi::QueryBuilder::Mixins::Sort::Param
- Defined in:
- lib/jsonapi/query_builder/mixins/sort/param.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#descending ⇒ Object
readonly
Returns the value of attribute descending.
Class Method Summary collapse
Instance Method Summary collapse
- #deserialize(param) ⇒ Object
- #direction ⇒ Object
-
#initialize(param) ⇒ Param
constructor
A new instance of Param.
- #serialize ⇒ Object
Constructor Details
#initialize(param) ⇒ Param
Returns a new instance of Param.
10 11 12 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 10 def initialize(param) @descending, @attribute = deserialize(param) end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
8 9 10 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 8 def attribute @attribute end |
#descending ⇒ Object (readonly)
Returns the value of attribute descending.
8 9 10 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 8 def descending @descending end |
Class Method Details
.deserialize_params(sort_params) ⇒ Object
15 16 17 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 15 def deserialize_params(sort_params) (sort_params || "").split(",").map(&method(:new)) end |
Instance Method Details
#deserialize(param) ⇒ Object
20 21 22 23 24 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 20 def deserialize(param) _, descending, attribute = param.strip.match(/^(?<descending>-)?(?<attribute>.*)$/).to_a [descending, attribute] end |
#direction ⇒ Object
30 31 32 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 30 def direction descending.present? ? :desc : :asc end |
#serialize ⇒ Object
26 27 28 |
# File 'lib/jsonapi/query_builder/mixins/sort/param.rb', line 26 def serialize [descending, attribute].compact.join end |