aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/relations/selection.rb
blob: 93e0e16dc5276ac960aa14ea17b209be336a08ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module ActiveRelation
  class Selection < Compound
    attr_reader :predicate

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

    def ==(other)
      self.class == other.class and
      relation   == other.relation and
      predicate  == other.predicate
    end
    
    protected
    def selects
      relation.send(:selects) + [predicate]
    end
    
    def __collect__(&block)
      Selection.new(relation.__collect__(&block), yield(predicate))
    end
    
  end
end