mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
getting rid of InstanceMethods anti-pattern...
This commit is contained in:
parent
45b2079e6a
commit
b3eefb7219
1 changed files with 25 additions and 31 deletions
|
@ -1,42 +1,36 @@
|
|||
module DatabaseCleaner
|
||||
module Generic
|
||||
module Truncation
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
def initialize(opts={})
|
||||
if !opts.empty? && !(opts.keys - [:only, :except]).empty?
|
||||
raise ArgumentError, "The only valid options are :only and :except. You specified #{opts.keys.join(',')}."
|
||||
end
|
||||
if opts.has_key?(:only) && opts.has_key?(:except)
|
||||
raise ArgumentError, "You may only specify either :only or :either. Doing both doesn't really make sense does it?"
|
||||
end
|
||||
|
||||
@only = opts[:only]
|
||||
@tables_to_exclude = (opts[:except] || []).dup
|
||||
@tables_to_exclude << migration_storage_name if migration_storage_name
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def initialize(opts={})
|
||||
if !opts.empty? && !(opts.keys - [:only, :except]).empty?
|
||||
raise ArgumentError, "The only valid options are :only and :except. You specified #{opts.keys.join(',')}."
|
||||
end
|
||||
if opts.has_key?(:only) && opts.has_key?(:except)
|
||||
raise ArgumentError, "You may only specify either :only or :either. Doing both doesn't really make sense does it?"
|
||||
end
|
||||
def start
|
||||
#included for compatability reasons, do nothing if you don't need to
|
||||
end
|
||||
|
||||
@only = opts[:only]
|
||||
@tables_to_exclude = (opts[:except] || []).dup
|
||||
@tables_to_exclude << migration_storage_name if migration_storage_name
|
||||
end
|
||||
def clean
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def start
|
||||
#included for compatability reasons, do nothing if you don't need to
|
||||
end
|
||||
private
|
||||
def tables_to_truncate
|
||||
raise NotImplementedError
|
||||
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
|
||||
# overwrite in subclasses
|
||||
# default implementation given because migration storage need not be present
|
||||
def migration_storage_name
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue