class DatabaseCleaner::Cleaners

Public Class Methods

new(hash={}) click to toggle source
Calls superclass method
# File lib/database_cleaner/cleaners.rb, line 6
def initialize hash={}
  super.replace(hash)
end

Public Instance Methods

[](orm, **opts) click to toggle source

FIXME this method conflates creation with lookup… both a command and a query. yuck.

# File lib/database_cleaner/cleaners.rb, line 11
def [](orm, **opts)
  raise ArgumentError if orm.nil?
  fetch([orm, opts]) { add_cleaner(orm, **opts) }
end
clean() click to toggle source
# File lib/database_cleaner/cleaners.rb, line 26
def clean
  Safeguard.new.run
  values.each { |cleaner| cleaner.clean }
end
clean_with(*args) click to toggle source
# File lib/database_cleaner/cleaners.rb, line 38
def clean_with(*args)
  Safeguard.new.run
  values.each { |cleaner| cleaner.clean_with(*args) }
end
cleaning(&inner_block) click to toggle source
# File lib/database_cleaner/cleaners.rb, line 31
def cleaning(&inner_block)
  Safeguard.new.run
  values.inject(inner_block) do |curr_block, cleaner|
    proc { cleaner.cleaning(&curr_block) }
  end.call
end
start() click to toggle source
# File lib/database_cleaner/cleaners.rb, line 21
def start
  Safeguard.new.run
  values.each { |cleaner| cleaner.start }
end
strategy=(strategy) click to toggle source
# File lib/database_cleaner/cleaners.rb, line 16
def strategy=(strategy)
  values.each { |cleaner| cleaner.strategy = strategy }
  remove_duplicates
end

Private Instance Methods

add_cleaner(orm, **opts) click to toggle source
# File lib/database_cleaner/cleaners.rb, line 45
def add_cleaner(orm, **opts)
  self[[orm, opts]] = Cleaner.new(orm, **opts)
end
remove_duplicates() click to toggle source
# File lib/database_cleaner/cleaners.rb, line 49
def remove_duplicates
  replace(reduce(Cleaners.new) do |cleaners, (key, value)|
    cleaners[key] = value unless cleaners.values.include?(value)
    cleaners
  end)
end