class TestProf::AnyFixture::Dump

Attributes

digest[R]
name[R]
path[R]
subscriber[R]
success[R]
success?[R]

Public Class Methods

new(name, watch: [], cache_key: nil) click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 116
def initialize(name, watch: [], cache_key: nil)
  @name = name
  @digest = [
    Digest.call(*watch),
    cache_key.to_digest
  ].compact.join("-")

  @path = build_path(name, digest)

  @success = false

  @adapter =
    case ActiveRecord::Base.connection.adapter_name
    when /sqlite/i
      require "test_prof/any_fixture/dump/sqlite"
      SQLite.new
    when /postgresql/i
      require "test_prof/any_fixture/dump/postgresql"
      PostgreSQL.new
    else
      raise ArgumentError,
        "Your current database adapter (#{ActiveRecord::Base.connection.adapter_name}) " \
        "is currently not supported. So far, we only support SQLite and PostgreSQL"
    end

  @subscriber = Subscriber.new(path, adapter)
end

Public Instance Methods

commit!() click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 158
def commit!
  subscriber.commit
end
exists?() click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 144
def exists?
  File.exist?(path)
end
force?() click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 148
def force?
  AnyFixture.config.force_matching_dumps.match?(name)
end
load() click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 152
def load
  return import_via_active_record unless AnyFixture.config.import_dump_via_cli?

  adapter.import(path) || import_via_active_record
end
within_prepared_env(before: nil, after: nil, import: false) { || ... } click to toggle source
# File lib/test_prof/any_fixture/dump.rb, line 162
def within_prepared_env(before: nil, after: nil, import: false)
  run_before_callbacks(callback: before, dump: self, import: false)
  yield.tap do
    @success = true
  end