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

       
                  
                                                        
       
 
                       
                                                                                                        
       
 


                                                           
     
   
module Arel
  class Project < Compound
    attr_reader :projections

    def initialize(relation, *projections)
      super(relation)
      @projections = projections.collect { |p| p.bind(relation) }
      @attributes = nil
    end

    def attributes
      @attributes ||= Header.new(projections).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