aboutsummaryrefslogblamecommitdiffstats
path: root/lib/arel/algebra/relations/operations/project.rb
blob: 1c24ae6caff7395af69003b06dc50ef594a3e51b (plain) (tree)
1
2
3
4
5
6
7
8
9
           
                          
                                                      
 
                                         
                     
                                                             
                                       
                                                                    
       
 
                       
                                                                                                        
       
 


                                                           
     
   
module Arel
  class Project < Compound
    attr_reader :projections, :attributes, :christener

    def initialize(relation, projections)
      super(relation)
      @projections = projections.map { |p| p.bind(relation) }
      @christener = Sql::Christener.new
      @attributes = Header.new(projections.map { |x| x.bind(self) })
    end

    def externalizable?
      attributes.any? { |a| a.respond_to?(:aggregation?) && a.aggregation? } || relation.externalizable?
    end

    def eval
      unoperated_rows.collect { |r| r.slice(*projections) }
    end
  end
end