getting rid of InstanceMethods anti-pattern...

This commit is contained in:
Ben Mabey 2011-12-19 20:30:04 -07:00
parent 45b2079e6a
commit b3eefb7219

View file

@ -1,42 +1,36 @@
module DatabaseCleaner module DatabaseCleaner
module Generic module Generic
module Truncation module Truncation
def self.included(base) def initialize(opts={})
base.send(:include, InstanceMethods) 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 end
module InstanceMethods def start
def initialize(opts={}) #included for compatability reasons, do nothing if you don't need to
if !opts.empty? && !(opts.keys - [:only, :except]).empty? end
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] def clean
@tables_to_exclude = (opts[:except] || []).dup raise NotImplementedError
@tables_to_exclude << migration_storage_name if migration_storage_name end
end
def start private
#included for compatability reasons, do nothing if you don't need to def tables_to_truncate
end raise NotImplementedError
end
def clean # overwrite in subclasses
raise NotImplementedError # default implementation given because migration storage need not be present
end def migration_storage_name
nil
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 end
end end
end end