class Gamera::Utils::DatabaseCleaner

Cleans a database by truncating the tables

Usage:

Gamera::Utils::DatabaseCleaner.new(connection).clean

Or:

Gamera::Utils::DatabaseCleaner.new(connection, tables).clean

connection is a Sequel database connection. tables is an array of table names (string or symbol).

If tables is given, only the tables supplied will be truncated. If tables is not given, all tables in the database will be truncated.

Attributes

db[R]
tables[R]

Public Class Methods

new(connection, tables = nil) click to toggle source
# File lib/gamera/utils/database_cleaner.rb, line 49
def initialize(connection, tables = nil)
  @db = connection
  @tables = tables || all_table_names
end

Public Instance Methods

clean() click to toggle source

Removes all data from the initialized tables. If no tables were given, removes all data from all tables in the database.

Cleans via truncation.

# File lib/gamera/utils/database_cleaner.rb, line 59
def clean
  tables.each do |table|
    db[table].truncate
  end
  nil
end

Private Instance Methods

all_table_names() click to toggle source
# File lib/gamera/utils/database_cleaner.rb, line 70
def all_table_names
  db.tables
end