class DatabaseFlusher::ActiveRecord::DeletionStrategy

Attributes

tables[R]

Public Class Methods

new() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 43
def initialize
  @tables = Set.new
end

Public Instance Methods

clean() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 61
def clean
  return if tables.empty?

  # puts "Cleaning #{tables.inspect}"
  adapter.delete(*tables)

  tables.clear
end
clean_all() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 70
def clean_all
  adapter.delete(*all_tables)
end
start() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 47
def start
  @subscriber ||= ActiveSupport::Notifications.subscribe(
    'sql.active_record',
    Subscriber.new(self)
  )
end
stop() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 54
def stop
  if @subscriber
    ActiveSupport::Notifications.unsubscribe(@subscriber)
    @subscriber = nil
  end
end

Private Instance Methods

adapter() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 80
def adapter
  @adapter ||= DatabaseFlusher::ActiveRecord.
    const_get("#{connection.adapter_name}Adapter").
    new(connection)
end
all_tables() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 86
def all_tables
  # NOTE connection.tables warns on AR 5 with some adapters
  tables = ActiveSupport::Deprecation.silence { connection.tables }
  tables.reject do |t|
    (t == ::ActiveRecord::SchemaMigration.table_name) ||
      (::ActiveRecord::Base.respond_to?(:internal_metadata_table_name) &&
      (t == ::ActiveRecord::Base.internal_metadata_table_name))
  end
end
connection() click to toggle source
# File lib/database_flusher/active_record/deletion_strategy.rb, line 76
def connection
  @connection ||= ::ActiveRecord::Base.connection
end