aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/project.rb
blob: 0590b8dd88b70b838e07f64be3c14c977c3bd822 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Arel
  class Project < Compound
    attr_reader :projections, :attributes

    def initialize(relation, *projections)
      super(relation)
      @projections = projections.map { |p| p.bind(relation) }
      @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