aboutsummaryrefslogblamecommitdiffstats
path: root/lib/active_relation/relations/selection.rb
blob: 032de63d043a0f772a8d9aaad06f5c96357b8df4 (plain) (tree)
1
2
3
4
5
6
7
8
                     



                                         
                                  
                                                                                    
                                            


                 


                                      
       
    

                                                               

       
               
                                    
           

     
module ActiveRelation
  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 descend(&block)
      Selection.new(relation.descend(&block), yield(predicate))
    end
    
    def selects
      relation.selects + [predicate]
    end    
  end
end