aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/relations/order.rb
blob: b5495fad67ca15b105a43ed6d907960a0ea208d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module ActiveRelation
  class Order < Compound
    attr_reader :ordering

    def initialize(relation, *orders)
      ordering = orders.pop
      @relation = orders.empty?? relation : Order.new(relation, *orders)
      @ordering = ordering.bind(@relation)
    end

    def ==(other)
      self.class  == other.class    and
      relation    == other.relation and
      ordering    == other.ordering
    end
    
    def orders
      relation.orders + [ordering]
    end
  end
end