blob: 4682298608bcc3c210a5d6ef137081cb81c1b914 (
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
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
|
module ActiveRelation
class Table < Relation
cattr_accessor :engine
attr_reader :name, :engine
hash_on :name
def initialize(name, engine = Table.engine)
@name, @engine = name.to_s, engine
end
def attributes
@attributes ||= columns.collect do |column|
Attribute.new(self, column.name.to_sym)
end
end
def qualify
Rename.new self, qualifications
end
def prefix_for(attribute)
self[attribute] and name
end
def column_for(attribute)
self[attribute] and columns.detect { |c| c.name == attribute.name.to_s }
end
def ==(other)
self.class == other.class and
name == other.name
end
def columns
@columns ||= engine.columns(name, "#{name} Columns")
end
def descend
yield self
end
def reset
@attributes = @columns = nil
end
protected
def table_sql
"#{engine.quote_table_name(name)}"
end
private
def qualifications
attributes.zip(attributes.collect(&:qualified_name)).to_hash
end
end
end
|