class DataMapper::Query::Sort

Attributes

value[R]

@api semipublic

Public Class Methods

new(value, ascending = true) click to toggle source

@api private

# File lib/dm-core/query/sort.rb, line 33
def initialize(value, ascending = true)
  @value     = value
  @ascending = ascending
end

Public Instance Methods

<=>(other) click to toggle source

@api private

# 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 = case
    when value_nil then other_nil ? 0 : 1
    when other_nil then -1
    else
      @value <=> other_value
  end

  @ascending ? cmp : cmp * -1
end
direction() click to toggle source

@api semipublic

# File lib/dm-core/query/sort.rb, line 10
def direction
  @ascending ? :ascending : :descending
end