Class: Arel::Table
Constant Summary
collapse
- @@engine =
nil
- @@tables =
nil
Instance Attribute Summary collapse
Attributes included from Relation
#count
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Relation
#[], #alias, #bind, #call, #compiler, #delete, #each, #exclusion_predicate_sql, #externalizable?, #externalize, #find_attribute_matching_name, #from, #from_clauses, #group_clauses, #groupings, #having_clauses, #havings, #inclusion_predicate_sql, #insert, #inserts, #join, #join?, #joins, #lock, #locked, #order_clauses, #orders, #outer_join, #position_of, #primary_key, #project, #projections, #select_clauses, #session, #skip, #skipped, #sources, #take, #taken, #to_sql, #update, #where, #where_clauses, #wheres
#table, #table_sql
Constructor Details
#initialize(name, options = {}) ⇒ Table
Returns a new instance of Table.
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
|
# File 'lib/arel/engines/sql/relations/table.rb', line 17
def initialize(name, options = {})
@name = name.to_s
@table_exists = nil
@table_alias = nil
@christener = Sql::Christener.new
@attributes = nil
@matching_attributes = nil
if options.is_a?(Hash)
@options = options
@engine = options[:engine] || Table.engine
if options[:as]
as = options[:as].to_s
@table_alias = as unless as == @name
end
else
@engine = options end
if @engine.connection
begin
require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
rescue LoadError
begin
require "#{@engine.adapter_name.downcase}/arel_compiler"
rescue LoadError
raise "#{@engine.adapter_name} is not supported by Arel."
end
end
@@tables ||= engine.connection.tables
end
end
|
Instance Attribute Details
#christener ⇒ Object
Returns the value of attribute christener.
15
16
17
|
# File 'lib/arel/engines/sql/relations/table.rb', line 15
def christener
@christener
end
|
#engine ⇒ Object
Returns the value of attribute engine.
15
16
17
|
# File 'lib/arel/engines/sql/relations/table.rb', line 15
def engine
@engine
end
|
#name ⇒ Object
Returns the value of attribute name.
15
16
17
|
# File 'lib/arel/engines/sql/relations/table.rb', line 15
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
15
16
17
|
# File 'lib/arel/engines/sql/relations/table.rb', line 15
def options
@options
end
|
#table_alias ⇒ Object
Returns the value of attribute table_alias.
15
16
17
|
# File 'lib/arel/engines/sql/relations/table.rb', line 15
def table_alias
@table_alias
end
|
Class Method Details
.engine ⇒ Object
8
|
# File 'lib/arel/engines/sql/relations/table.rb', line 8
def engine; @@engine; end
|
.engine=(e) ⇒ Object
9
|
# File 'lib/arel/engines/sql/relations/table.rb', line 9
def engine= e; @@engine = e; end
|
.tables ⇒ Object
11
|
# File 'lib/arel/engines/sql/relations/table.rb', line 11
def tables; @@tables; end
|
.tables=(e) ⇒ Object
12
|
# File 'lib/arel/engines/sql/relations/table.rb', line 12
def tables= e; @@tables = e; end
|
Instance Method Details
#as(table_alias) ⇒ Object
53
54
55
|
# File 'lib/arel/engines/sql/relations/table.rb', line 53
def as(table_alias)
Table.new(name, options.merge(:as => table_alias))
end
|
#attributes ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/arel/engines/sql/relations/table.rb', line 61
def attributes
return @attributes if @attributes
if table_exists?
attrs = columns.collect do |column|
Sql::Attributes.for(column).new(column, self, column.name.to_sym)
end
@attributes = Header.new(attrs)
else
Header.new
end
end
|
#column_for(attribute) ⇒ Object
73
74
75
|
# File 'lib/arel/engines/sql/relations/table.rb', line 73
def column_for(attribute)
has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
end
|
#columns ⇒ Object
77
78
79
|
# File 'lib/arel/engines/sql/relations/table.rb', line 77
def columns
@columns ||= engine.connection.columns(name, "#{name} Columns")
end
|
#reset ⇒ Object
81
82
83
84
|
# File 'lib/arel/engines/sql/relations/table.rb', line 81
def reset
@columns = nil
@attributes = Header.new([])
end
|
#table_exists? ⇒ Boolean
57
58
59
|
# File 'lib/arel/engines/sql/relations/table.rb', line 57
def table_exists?
@table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name)
end
|