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 ⇒ Hash
It returns a hash with all the strategies associated with all the cleaners.
- #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
45 46 47 48 |
# File 'lib/database_cleaner/cleaners.rb', line 45 def clean Safeguard.new.run values.each { |cleaner| cleaner.clean } end |
#clean_with(*args) ⇒ Object
57 58 59 60 |
# File 'lib/database_cleaner/cleaners.rb', line 57 def clean_with(*args) Safeguard.new.run values.each { |cleaner| cleaner.clean_with(*args) } end |
#cleaning(&inner_block) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/database_cleaner/cleaners.rb', line 50 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
40 41 42 43 |
# File 'lib/database_cleaner/cleaners.rb', line 40 def start Safeguard.new.run values.each { |cleaner| cleaner.start } end |
#strategy ⇒ Hash
It returns a hash with all the strategies associated with all the cleaners.
For example:
“‘ cleaners.strategy
>
:active_record_1 => :truncation,
:active_record_2 => :truncation,
:data_mapper_1 => :truncation
:active_record_1 => :truncation,
:active_record_2 => :truncation,
:data_mapper_1 => :truncation
“‘
31 32 33 |
# File 'lib/database_cleaner/cleaners.rb', line 31 def strategy transform_values(&:strategy) end |
#strategy=(strategy) ⇒ Object
35 36 37 38 |
# File 'lib/database_cleaner/cleaners.rb', line 35 def strategy=(strategy) values.each { |cleaner| cleaner.strategy = strategy } remove_duplicates end |