Class: Gamera::Utils::DatabaseCleaner
- Inherits:
-
Object
- Object
- Gamera::Utils::DatabaseCleaner
- Defined in:
- lib/gamera/utils/database_cleaner.rb
Overview
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.
Instance Method Summary collapse
-
#clean ⇒ Object
Removes all data from the initialized tables.
-
#initialize(connection, tables = nil) ⇒ DatabaseCleaner
constructor
A new instance of DatabaseCleaner.
Constructor Details
#initialize(connection, tables = nil) ⇒ DatabaseCleaner
Returns a new instance of DatabaseCleaner.
49 50 51 52 |
# File 'lib/gamera/utils/database_cleaner.rb', line 49 def initialize(connection, tables = nil) @db = connection @tables = tables || all_table_names end |
Instance Method Details
#clean ⇒ Object
Removes all data from the initialized tables. If no tables were given, removes all data from all tables in the database.
Cleans via truncation.
59 60 61 62 63 64 |
# File 'lib/gamera/utils/database_cleaner.rb', line 59 def clean tables.each do |table| db[table].truncate end nil end |