aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/utilities/compound.rb
blob: 1a43c76a947485c6f6401454b7d34b67646d4283 (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 Compound < Relation
    attr_reader :relation
    delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?,
             :column_for, :engine, :sources, :locked, :table_alias,
             :to => :relation

    [:attributes, :wheres, :groupings, :orders, :havings, :projections].each do |operation_name|
      class_eval <<-OPERATION, __FILE__, __LINE__
        def #{operation_name}
          @#{operation_name} ||= relation.#{operation_name}.collect { |o| o.bind(self) }
        end
      OPERATION
    end

    def hash
      @hash ||= :relation.hash
    end

    def eql?(other)
      self == other
    end

  private

    def arguments_from_block(relation, &block)
      block_given?? [yield(relation)] : []
    end
  end
end