aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/project.rb
blob: daca7420390c4c41737f5e765659281481c6fe5b (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
27
28
29
30
module Arel
  class Project < Compound
    attr_reader :projections

    def initialize(relation, *projections, &block)
      super(relation)
      @projections = (projections + arguments_from_block(relation, &block)) \
        .collect { |p| p.bind(relation) }
    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 == other
      super ||
        Project === other &&
        relation == other.relation &&
        projections == other.projections
    end

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