Class: DatabaseCleaner::Cleaners
- Inherits:
-
Hash
- Object
- Hash
- DatabaseCleaner::Cleaners
- Defined in:
- lib/database_cleaner/cleaners.rb
Instance Method Summary collapse
-
#[](orm, **opts) ⇒ Object
FIXME this method conflates creation with lookup…
- #clean ⇒ Object
- #clean_with(*args) ⇒ Object
- #cleaning(&inner_block) ⇒ Object
-
#initialize(hash = {}) ⇒ Cleaners
constructor
A new instance of Cleaners.
- #start ⇒ Object
- #strategy=(strategy) ⇒ Object
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.
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 |
#clean ⇒ Object
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 |
#start ⇒ Object
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 |