class ActiveAny::Relation::OrderClause

Constants

OrderValue

Attributes

order_values[R]

Public Class Methods

empty() click to toggle source
# File lib/active_any/relation/order_clause.rb, line 6
def self.empty
  new
end
new(values = [], reverse = false) click to toggle source
# File lib/active_any/relation/order_clause.rb, line 14
def initialize(values = [], reverse = false)
  @reverse = reverse
  @order_values = convert_order_values(values)
end

Public Instance Methods

+(other) click to toggle source
# File lib/active_any/relation/order_clause.rb, line 28
def +(other)
  OrderClause.new(
    order_values + other.order_values,
    reverse? || other.reverse?
  )
end
Also aliased as: merge
==(other) click to toggle source
# File lib/active_any/relation/order_clause.rb, line 37
def ==(other)
  reverse? == other.reverse? && order_values == other.order_values
end
empty?() click to toggle source
# File lib/active_any/relation/order_clause.rb, line 41
def empty?
  order_values.empty?
end
merge(other)
Alias for: +
reverse!() click to toggle source
# File lib/active_any/relation/order_clause.rb, line 23
def reverse!
  @reverse = true
  self
end
reverse?() click to toggle source
# File lib/active_any/relation/order_clause.rb, line 19
def reverse?
  @reverse
end

Private Instance Methods

convert_order_values(values) click to toggle source
# File lib/active_any/relation/order_clause.rb, line 47
def convert_order_values(values)
  values.map do |arg|
    case arg
    when ::Hash then OrderValue.new(arg.keys.first, arg.values.first)
    when ::Symbol, ::String then OrderValue.new(arg, :asc)
    when OrderValue then arg
    else
      raise ArgumentError
    end
  end
end