Class: ActiveRecord::ConnectionAdapters::SchemaReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/schema_cache.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_path, cache = nil) ⇒ SchemaReflection

Returns a new instance of SchemaReflection.



16
17
18
19
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 16

def initialize(cache_path, cache = nil)
  @cache = cache
  @cache_path = cache_path
end

Class Attribute Details

.check_schema_cache_dump_versionObject

Returns the value of attribute check_schema_cache_dump_version.



10
11
12
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 10

def check_schema_cache_dump_version
  @check_schema_cache_dump_version
end

.use_schema_cache_dumpObject

Returns the value of attribute use_schema_cache_dump.



9
10
11
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 9

def use_schema_cache_dump
  @use_schema_cache_dump
end

Instance Method Details

#add(connection, name) ⇒ Object



45
46
47
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 45

def add(connection, name)
  cache(connection).add(connection, name)
end

#cached?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 87

def cached?(table_name)
  if @cache.nil?
    # If `check_schema_cache_dump_version` is enabled we can't load
    # the schema cache dump without connecting to the database.
    unless self.class.check_schema_cache_dump_version
      @cache = load_cache(nil)
    end
  end

  @cache&.cached?(table_name)
end

#clear!Object



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

def clear!
  @cache = empty_cache

  nil
end

#clear_data_source_cache!(connection, name) ⇒ Object



81
82
83
84
85
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 81

def clear_data_source_cache!(connection, name)
  return if @cache.nil? && !possible_cache_available?

  cache(connection).clear_data_source_cache!(connection, name)
end

#columns(connection, table_name) ⇒ Object



53
54
55
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 53

def columns(connection, table_name)
  cache(connection).columns(connection, table_name)
end

#columns_hash(connection, table_name) ⇒ Object



57
58
59
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 57

def columns_hash(connection, table_name)
  cache(connection).columns_hash(connection, table_name)
end

#columns_hash?(connection, table_name) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 61

def columns_hash?(connection, table_name)
  cache(connection).columns_hash?(connection, table_name)
end

#data_source_exists?(connection, name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 41

def data_source_exists?(connection, name)
  cache(connection).data_source_exists?(connection, name)
end

#data_sources(connection, name) ⇒ Object



49
50
51
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 49

def data_sources(connection, name)
  cache(connection).data_sources(connection, name)
end

#database_version(connection) ⇒ Object

:nodoc:



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

def database_version(connection) # :nodoc:
  cache(connection).database_version(connection)
end

#dump_to(connection, filename) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 99

def dump_to(connection, filename)
  fresh_cache = empty_cache
  fresh_cache.add_all(connection)
  fresh_cache.dump_to(filename)

  @cache = fresh_cache
end

#indexes(connection, table_name) ⇒ Object



65
66
67
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 65

def indexes(connection, table_name)
  cache(connection).indexes(connection, table_name)
end

#load!(connection) ⇒ Object



31
32
33
34
35
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 31

def load!(connection)
  cache(connection)

  self
end

#primary_keys(connection, table_name) ⇒ Object



37
38
39
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 37

def primary_keys(connection, table_name)
  cache(connection).primary_keys(connection, table_name)
end

#set_schema_cache(cache) ⇒ Object



21
22
23
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 21

def set_schema_cache(cache)
  @cache = cache
end

#size(connection) ⇒ Object



77
78
79
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 77

def size(connection)
  cache(connection).size
end

#version(connection) ⇒ Object



73
74
75
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 73

def version(connection)
  cache(connection).version(connection)
end