Class: ActiveRecord::ConnectionAdapters::Sqlserver::SchemaCache

Inherits:
ActiveRecord::ConnectionAdapters::SchemaCache
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlserver/schema_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ SchemaCache

Returns a new instance of SchemaCache.



8
9
10
11
12
13
14
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 8

def initialize(conn)
  super
  @table_names = nil
  @view_names = nil
  @view_information = {}
  @quoted_names = {}
end

Instance Attribute Details

#view_information(table_name) ⇒ Object (readonly)

Returns the value of attribute view_information.



6
7
8
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 6

def view_information
  @view_information
end

Instance Method Details

#clear!Object



25
26
27
28
29
30
31
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 25

def clear!
  super
  @table_names = nil
  @view_names = nil
  @view_information.clear
  @quoted_names.clear
end

#clear_table_cache!(table_name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 33

def clear_table_cache!(table_name)
  key = table_name_key(table_name)
  super(key)
  super(table_name)
  # SQL Server Specific
  if @table_names
    @table_names.delete key
    @table_names.delete table_name
  end
  if @view_names
    @view_names.delete key
    @view_names.delete table_name
  end
  @view_information.delete key
end

#quote_name(name) ⇒ Object



69
70
71
72
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 69

def quote_name(name)
  return @quoted_names[name] if @quoted_names.key? name
  @quoted_names[name] = name.to_s.split('.').map{ |n| n =~ /^\[.*\]$/ ? n : "[#{n.to_s.gsub(']', ']]')}]" }.join('.')
end

#table_exists?(table_name) ⇒ Boolean

Superclass Overrides

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 18

def table_exists?(table_name)
  return false if table_name.blank?
  key = table_name_key(table_name)
  return @tables[key] if @tables.key? key
  @tables[key] = connection.table_exists?(table_name)
end

#table_namesObject

SQL Server Specific



51
52
53
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 51

def table_names
  @table_names ||= connection.tables
end

#view_exists?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 59

def view_exists?(table_name)
  table_exists?(table_name)
end

#view_namesObject



55
56
57
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 55

def view_names
  @view_names ||= connection.views
end