Class: DatabaseCleaner::Cleaners
- Inherits:
-
Hash
- Object
- Hash
- DatabaseCleaner::Cleaners
- Defined in:
- lib/database_cleaner/configuration.rb
Instance Method Summary collapse
-
#[](orm, opts = {}) ⇒ Object
FIXME this method conflates creation with lookup…
-
#add_cleaner(orm, opts = {}) ⇒ Object
TODO privatize the following methods in 2.0.
- #orm=(orm) ⇒ Object
- #remove_duplicates ⇒ Object
- #strategy=(strategy) ⇒ Object
Instance Method Details
#[](orm, opts = {}) ⇒ Object
FIXME this method conflates creation with lookup… both a command and a query. yuck.
12 13 14 15 |
# File 'lib/database_cleaner/configuration.rb', line 12 def [](orm, opts = {}) raise NoORMDetected unless orm fetch([orm, opts]) { add_cleaner(orm, opts) } end |
#add_cleaner(orm, opts = {}) ⇒ Object
TODO privatize the following methods in 2.0
31 32 33 |
# File 'lib/database_cleaner/configuration.rb', line 31 def add_cleaner(orm, opts = {}) self[[orm, opts]] = ::DatabaseCleaner::Base.new(orm, opts) end |
#orm=(orm) ⇒ Object
23 24 25 26 27 |
# File 'lib/database_cleaner/configuration.rb', line 23 def orm=(orm) add_cleaner(:autodetect) if none? values.each { |cleaner| cleaner.orm = orm } remove_duplicates end |
#remove_duplicates ⇒ Object
35 36 37 38 39 40 |
# File 'lib/database_cleaner/configuration.rb', line 35 def remove_duplicates replace(reduce(Cleaners.new) do |cleaners, (key, value)| cleaners[key] = value unless cleaners.values.include?(value) cleaners end) end |
#strategy=(strategy) ⇒ Object
17 18 19 20 21 |
# File 'lib/database_cleaner/configuration.rb', line 17 def strategy=(strategy) add_cleaner(:autodetect) if none? values.each { |cleaner| cleaner.strategy = strategy } remove_duplicates end |