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(pool, name) ⇒ Object



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

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

#cached?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/active_record/connection_adapters/schema_cache.rb', line 79

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



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

def clear!
  @cache = empty_cache

  nil
end

#clear_data_source_cache!(pool, name) ⇒ Object



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

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

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

#columns(pool, table_name) ⇒ Object



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

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

#columns_hash(pool, table_name) ⇒ Object



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

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

#columns_hash?(pool, table_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#data_source_exists?(pool, name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#data_sources(pool, name) ⇒ Object



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

def data_sources(pool, name)
  cache(pool).data_source_exists?(pool, name)
end

#dump_to(pool, filename) ⇒ Object



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

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

  @cache = fresh_cache
end

#indexes(pool, table_name) ⇒ Object



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

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

#load!(pool) ⇒ Object



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

def load!(pool)
  cache(pool)

  self
end

#primary_keys(pool, table_name) ⇒ Object



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

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

#size(pool) ⇒ Object



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

def size(pool)
  cache(pool).size
end

#version(pool) ⇒ Object



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

def version(pool)
  cache(pool).version(pool)
end