Class: Dbee::Query::Sorters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dbee/query/sorters/base.rb

Overview

Abstract representation of the ORDER BY part of a SQL statement.

Direct Known Subclasses

Ascending, Descending

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_path:) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/dbee/query/sorters/base.rb', line 19

def initialize(key_path:)
  raise ArgumentError, 'key_path is required' if key_path.to_s.empty?

  @key_path = KeyPath.get(key_path)

  freeze
end

Instance Attribute Details

#key_pathObject (readonly)

Returns the value of attribute key_path.



17
18
19
# File 'lib/dbee/query/sorters/base.rb', line 17

def key_path
  @key_path
end

Instance Method Details

#<=>(other) ⇒ Object



37
38
39
# File 'lib/dbee/query/sorters/base.rb', line 37

def <=>(other)
  "#{key_path}#{self.class.name}" <=> "#{other.key_path}#{other.class.name}"
end

#==(other) ⇒ Object Also known as: eql?



31
32
33
34
# File 'lib/dbee/query/sorters/base.rb', line 31

def ==(other)
  other.instance_of?(self.class) &&
    other.key_path == key_path
end

#hashObject



27
28
29
# File 'lib/dbee/query/sorters/base.rb', line 27

def hash
  "#{self.class.name}#{key_path}".hash
end