class ActiveRecord::ConnectionAdapters::SQLServer::SchemaCache

Public Class Methods

new(conn) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 6
def initialize(conn)
  super
  @views = {}
  @view_information = {}
end

Public Instance Methods

clear!() click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 43
def clear!
  super
  @views.clear
  @view_information.clear
end
clear_table_cache!(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 53
def clear_table_cache!(table_name)
  name = key(table_name)
  @columns.delete name
  @columns_hash.delete name
  @primary_keys.delete name
  @tables.delete name
  @views.delete name
  @view_information.delete name
end
columns(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 31
def columns(table_name)
  name = key(table_name)
  @columns[name] ||= connection.columns(table_name)
end
columns_hash(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 36
def columns_hash(table_name)
  name = key(table_name)
  @columns_hash[name] ||= Hash[columns(table_name).map { |col|
    [col.name, col]
  }]
end
marshal_dump() click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 63
def marshal_dump
  super + [@views, @view_information]
end
marshal_load(array) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 67
def marshal_load(array)
  @views, @view_information = array[-2..-1]
  super(array[0..-3])
end
primary_keys(table_name) click to toggle source

Superclass Overrides

# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 14
def primary_keys(table_name)
  name = key(table_name)
  @primary_keys[name] ||= table_exists?(table_name) ? connection.primary_key(table_name) : nil
end
size() click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 49
def size
  super + [@views, @view_information].map{ |x| x.size }.inject(:+)
end
table_exists?(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 19
def table_exists?(table_name)
  name = key(table_name)
  prepare_tables_and_views
  return @tables[name] if @tables.key? name
  table_exists = @tables[name] = connection.table_exists?(table_name)
  table_exists || view_exists?(table_name)
end
tables(name) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 27
def tables(name)
  super(key(name))
end
view_exists?(table_name) click to toggle source

SQL Server Specific

# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 74
def view_exists?(table_name)
  name = key(table_name)
  prepare_tables_and_views
  return @views[name] if @views.key? name
  @views[name] = connection.views.include?(table_name)
end
view_information(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 81
def view_information(table_name)
  name = key(table_name)
  return @view_information[name] if @view_information.key? name
  @view_information[name] = connection.send(:view_information, table_name)
end

Private Instance Methods

identifier(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 90
def identifier(table_name)
  SQLServer::Utils.extract_identifiers(table_name)
end
key(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 94
def key(table_name)
  identifier(table_name).quoted
end
prepare_tables() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 103
def prepare_tables
  connection.tables.each { |table| @tables[key(table)] = true }
end
prepare_tables_and_views() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 98
def prepare_tables_and_views
  prepare_views if @views.empty?
  prepare_tables if @tables.empty?
end
prepare_views() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/schema_cache.rb, line 107
def prepare_views
  connection.views.each { |view| @views[key(view)] = true }
end