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)



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

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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dm-core/query/sort.rb', line 15

def <=>(other)
  other_value = other.value
  value_nil   = @value.nil?
  other_nil   = other_value.nil?

  cmp = if value_nil
          other_nil ? 0 : 1
        elsif other_nil
          -1
        else
          @value <=> other_value
        end

  @ascending ? cmp : cmp * -1
end

#directionObject



10
11
12
# File 'lib/dm-core/query/sort.rb', line 10

def direction
  @ascending ? :ascending : :descending
end