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.



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

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:



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

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

#cleanObject



24
25
26
# File 'lib/database_cleaner/cleaners.rb', line 24

def clean
  values.each { |cleaner| cleaner.clean }
end

#clean_with(*args) ⇒ Object



34
35
36
# File 'lib/database_cleaner/cleaners.rb', line 34

def clean_with(*args)
  values.each { |cleaner| cleaner.clean_with(*args) }
end

#cleaning(&inner_block) ⇒ Object



28
29
30
31
32
# File 'lib/database_cleaner/cleaners.rb', line 28

def cleaning(&inner_block)
  values.inject(inner_block) do |curr_block, cleaner|
    proc { cleaner.cleaning(&curr_block) }
  end.call
end

#startObject



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

def start
  values.each { |cleaner| cleaner.start }
end

#strategy=(strategy) ⇒ Object



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

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