Class: Arel::Table
- Inherits:
-
Object
- Object
- Arel::Table
- Includes:
- Recursion::BaseCase, Relation
- Defined in:
- lib/arel/engines/sql/relations/table.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table_alias ⇒ Object
readonly
Returns the value of attribute table_alias.
Attributes included from Relation
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as(table_alias) ⇒ Object
- #attributes ⇒ Object
- #column_for(attribute) ⇒ Object
- #columns ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, options = {}) ⇒ Table
constructor
A new instance of Table.
- #reset ⇒ Object
- #table_exists? ⇒ Boolean
Methods included from Relation
#bind, #call, #christener, #compiler, #exclusion_predicate_sql, #externalizable?, #externalize, #inclusion_predicate_sql, #join?, #primary_key, #session, #to_sql
Methods included from Relation::DefaultOperations
#groupings, #havings, #inserts, #joins, #locked, #orders, #projections, #skipped, #sources, #taken, #wheres
Methods included from Relation::AttributeAccessable
#[], #find_attribute_matching_attribute, #find_attribute_matching_name, #position_of
Methods included from Relation::Operable
#alias, #join, #lock, #outer_join
Methods included from Relation::Operable::Writable
Methods included from Relation::Enumerable
Methods included from Recursion::BaseCase
Constructor Details
#initialize(name, options = {}) ⇒ Table
Returns a new instance of Table.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/arel/engines/sql/relations/table.rb', line 8 def initialize(name, = {}) @name = name.to_s @table_exists = nil if .is_a?(Hash) @options = @engine = [:engine] || Table.engine @table_alias = [:as].to_s if [:as].present? && [:as].to_s != @name else @engine = # Table.new('foo', engine) end if @engine.connection begin require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler" @@tables ||= engine.tables rescue LoadError raise "#{@engine.adapter_name} is not supported by Arel." end end end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
6 7 8 |
# File 'lib/arel/engines/sql/relations/table.rb', line 6 def engine @engine end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/arel/engines/sql/relations/table.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/arel/engines/sql/relations/table.rb', line 6 def @options end |
#table_alias ⇒ Object (readonly)
Returns the value of attribute table_alias.
6 7 8 |
# File 'lib/arel/engines/sql/relations/table.rb', line 6 def table_alias @table_alias end |
Instance Method Details
#==(other) ⇒ Object
77 78 79 80 81 |
# File 'lib/arel/engines/sql/relations/table.rb', line 77 def ==(other) Table === other and name == other.name and table_alias == other.table_alias end |
#as(table_alias) ⇒ Object
30 31 32 |
# File 'lib/arel/engines/sql/relations/table.rb', line 30 def as(table_alias) Table.new(name, .merge(:as => table_alias)) end |
#attributes ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/arel/engines/sql/relations/table.rb', line 42 def attributes return @attributes if defined?(@attributes) if table_exists? @attributes ||= begin attrs = columns.collect do |column| Sql::Attributes.for(column).new(column, self, column.name.to_sym) end Header.new(attrs) end else Header.new end end |
#column_for(attribute) ⇒ Object
64 65 66 |
# File 'lib/arel/engines/sql/relations/table.rb', line 64 def column_for(attribute) has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s } end |
#columns ⇒ Object
68 69 70 |
# File 'lib/arel/engines/sql/relations/table.rb', line 68 def columns @columns ||= engine.columns(name, "#{name} Columns") end |
#eql?(other) ⇒ Boolean
56 57 58 |
# File 'lib/arel/engines/sql/relations/table.rb', line 56 def eql?(other) self == other end |
#hash ⇒ Object
60 61 62 |
# File 'lib/arel/engines/sql/relations/table.rb', line 60 def hash @hash ||= :name.hash end |
#reset ⇒ Object
72 73 74 75 |
# File 'lib/arel/engines/sql/relations/table.rb', line 72 def reset @columns = nil @attributes = Header.new([]) end |
#table_exists? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/arel/engines/sql/relations/table.rb', line 34 def table_exists? if @table_exists true else @table_exists = @@tables.include?(name) || engine.table_exists?(name) end end |