Class: DatabaseCleaner::Cleaners

Inherits:
Hash
  • Object
show all
Defined in:
lib/database_cleaner/cleaners.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Cleaners

Returns a new instance of Cleaners.



6
7
8
# File 'lib/database_cleaner/cleaners.rb', line 6

def initialize hash={}
  super.replace(hash)
end

Instance Method Details

#[](orm, **opts) ⇒ Object

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

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/database_cleaner/cleaners.rb', line 11

def [](orm, **opts)
  raise ArgumentError if orm.nil?
  fetch([orm, opts]) { add_cleaner(orm, **opts) }
end

#cleanObject



26
27
28
29
# File 'lib/database_cleaner/cleaners.rb', line 26

def clean
  Safeguard.new.run
  values.each { |cleaner| cleaner.clean }
end

#clean_with(*args) ⇒ Object



38
39
40
41
# 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) ⇒ Object



31
32
33
34
35
36
# 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

#startObject



21
22
23
24
# File 'lib/database_cleaner/cleaners.rb', line 21

def start
  Safeguard.new.run
  values.each { |cleaner| cleaner.start }
end

#strategy=(strategy) ⇒ Object



16
17
18
19
# File 'lib/database_cleaner/cleaners.rb', line 16

def strategy=(strategy)
  values.each { |cleaner| cleaner.strategy = strategy }
  remove_duplicates
end