Class: DataMapper::Query::Sort

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-core/query/sort.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject (readonly)

TODO: document



8
9
10
# File 'lib/dm-core/query/sort.rb', line 8

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: document



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dm-core/query/sort.rb', line 18

def <=>(other)
  other_value = other.value

  cmp = case
    when @value.nil? && other_value.nil?
      0
    when @value.nil?
      1
    when other_value.nil?
      -1
    else
      @value <=> other_value
  end

  @ascending ? cmp : cmp * -1
end

#directionObject

TODO: document



12
13
14
# File 'lib/dm-core/query/sort.rb', line 12

def direction
  @ascending ? :ascending : :descending
end