mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Extracted TruncationBase into own file and only require it for the
strategies that need it.
This commit is contained in:
parent
612f33c738
commit
1f1c3452c5
4 changed files with 43 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
require "database_cleaner/truncation_base"
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
|
|
|
@ -92,8 +92,6 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
|
||||
# common base class for truncation strategies
|
||||
|
||||
class TruncationBase
|
||||
|
||||
def initialize(options = {})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "database_cleaner/truncation_base"
|
||||
|
||||
module DataMapper
|
||||
module Adapters
|
||||
|
||||
|
|
40
lib/database_cleaner/truncation_base.rb
Normal file
40
lib/database_cleaner/truncation_base.rb
Normal 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
|
||||
|
Loading…
Add table
Reference in a new issue