Class: Dbee::Query::Sorter
- Inherits:
-
Object
- Object
- Dbee::Query::Sorter
- Includes:
- Direction
- Defined in:
- lib/dbee/query/sorter.rb
Overview
Abstract representation of the ORDER BY part of a SQL statement.
Defined Under Namespace
Modules: Direction
Constant Summary
Constants included from Direction
Direction::ASCENDING, Direction::DESCENDING
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#key_path ⇒ Object
readonly
Returns the value of attribute key_path.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #ascending? ⇒ Boolean
- #descending? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(key_path:, direction: ASCENDING) ⇒ Sorter
constructor
A new instance of Sorter.
Constructor Details
#initialize(key_path:, direction: ASCENDING) ⇒ Sorter
Returns a new instance of Sorter.
26 27 28 29 30 31 32 33 |
# File 'lib/dbee/query/sorter.rb', line 26 def initialize(key_path:, direction: ASCENDING) raise ArgumentError, 'key_path is required' if key_path.to_s.empty? @direction = Direction.const_get(direction.to_s.upcase.to_sym) @key_path = KeyPath.get(key_path) freeze end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
24 25 26 |
# File 'lib/dbee/query/sorter.rb', line 24 def direction @direction end |
#key_path ⇒ Object (readonly)
Returns the value of attribute key_path.
24 25 26 |
# File 'lib/dbee/query/sorter.rb', line 24 def key_path @key_path end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/dbee/query/sorter.rb', line 47 def ==(other) other.key_path == key_path && other.direction == direction end |
#ascending? ⇒ Boolean
39 40 41 |
# File 'lib/dbee/query/sorter.rb', line 39 def ascending? !descending? end |
#descending? ⇒ Boolean
35 36 37 |
# File 'lib/dbee/query/sorter.rb', line 35 def descending? direction == DESCENDING end |
#hash ⇒ Object
43 44 45 |
# File 'lib/dbee/query/sorter.rb', line 43 def hash "#{key_path}#{direction}".hash end |