Extracted TruncationBase into own file and only require it for the

strategies that need it.
This commit is contained in:
Ben Mabey 2009-05-08 18:17:46 -06:00
parent 612f33c738
commit 1f1c3452c5
4 changed files with 43 additions and 2 deletions

View file

@ -1,3 +1,4 @@
require "database_cleaner/truncation_base"
module ActiveRecord
module ConnectionAdapters

View file

@ -92,8 +92,6 @@ module DatabaseCleaner
end
# common base class for truncation strategies
class TruncationBase
def initialize(options = {})

View file

@ -1,3 +1,5 @@
require "database_cleaner/truncation_base"
module DataMapper
module Adapters

View file

@ -0,0 +1,40 @@
class TruncationBase
def initialize(options = {})
if !options.empty? && !(options.keys - [:only, :except]).empty?
raise ArgumentError, "The only valid options are :only and :except. You specified #{options.keys.join(',')}."
end
if options.has_key?(:only) && options.has_key?(:except)
raise ArgumentError, "You may only specify either :only or :either. Doing both doesn't really make sense does it?"
end
@only = options[:only]
@tables_to_exclude = (options[:except] || [])
if migration_storage = migration_storage_name
@tables_to_exclude << migration_storage
end
end
def start
# no-op
end
def clean
raise NotImplementedError
end
private
def tables_to_truncate
raise NotImplementedError
end
# overwrite in subclasses
# default implementation given because migration storage need not be present
def migration_storage_name
nil
end
end