Module: ColdStorage::ArchiveModel

Defined in:
lib/cold_storage/archive_model.rb

Overview

Builds, and caches, the ActiveRecord class that reads and writes a mirrored table in the archive database.

Constant Summary collapse

MIRRORED_MACROS =
%i[has_many has_one belongs_to].freeze

Class Method Summary collapse

Class Method Details

.clear!Object



41
42
43
44
45
46
# File 'lib/cold_storage/archive_model.rb', line 41

def clear!
  MONITOR.synchronize do
    @cache = {}
    @sources = {}
  end
end

.for(source) ⇒ Class

Returns its counterpart in the archive database.

Parameters:

  • source (Class)

    an ActiveRecord model in the primary database

Returns:

  • (Class)

    its counterpart in the archive database



31
32
33
34
# File 'lib/cold_storage/archive_model.rb', line 31

def for(source)
  ArchiveRecord.connect!
  cache[source.table_name] || MONITOR.synchronize { cache[source.table_name] ||= build(source) }
end

.registered_source(const_name) ⇒ Object



37
38
39
# File 'lib/cold_storage/archive_model.rb', line 37

def registered_source(const_name)
  MONITOR.synchronize { sources[const_name.to_s] }
end