aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/selection.rb
blob: 38a40e1b769162a980a481e2a32c8c27dc3692dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Arel
  class Selection < Compound
    attr_reader :predicate

    def initialize(relation, *predicates)
      predicate = predicates.shift
      @relation = predicates.empty?? relation : Selection.new(relation, *predicates)
      @predicate = predicate.bind(@relation)
    end

    def ==(other)
      self.class == other.class and
      relation   == other.relation and
      predicate  == other.predicate
    end
    
    def selects
      relation.selects + [predicate]
    end    
  end
end