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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
module Arel
class Compound
include Relation
attr_reader :relation
delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?,
:column_for, :sources, :locked, :table_alias,
:to => :relation
def self.requires(feature = nil)
@requires ||= nil
@requires = feature if feature
@requires
end
def initialize relation
@relation = relation
end
[: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 attributes
@attributes ||= relation.attributes.bind(self)
end
def hash
@hash ||= :relation.hash
end
def eql?(other)
self == other
end
def engine
requires = self.class.requires
engine = relation.engine
# Temporary check of whether or not the engine supports where.
if requires && engine.respond_to?(:supports) && !engine.supports(requires)
Memory::Engine.new
else
engine
end
end
private
def arguments_from_block(relation)
block_given?? [yield(relation)] : []
end
end
end
|