Class: DatabaseCleaner::Base
- Inherits:
-
Object
- Object
- DatabaseCleaner::Base
- Defined in:
- lib/database_cleaner/base.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
TODO make strategies directly comparable.
- #auto_detected? ⇒ Boolean
- #clean ⇒ Object (also: #clean!)
- #clean_with(*args) ⇒ Object (also: #clean_with!)
- #create_strategy(*args) ⇒ Object
- #db ⇒ Object
- #db=(desired_db) ⇒ Object
-
#initialize(desired_orm = nil, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #orm ⇒ Object
- #orm=(desired_orm) ⇒ Object
- #start ⇒ Object
- #strategy ⇒ Object
- #strategy=(args) ⇒ Object
- #strategy_db=(desired_db) ⇒ Object
Constructor Details
#initialize(desired_orm = nil, opts = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 |
# File 'lib/database_cleaner/base.rb', line 5 def initialize(desired_orm = nil,opts = {}) if [:autodetect, nil, "autodetect"].include?(desired_orm) autodetect else self.orm = desired_orm end self.db = opts[:connection] if opts.has_key? :connection set_default_orm_strategy end |
Instance Method Details
#==(other) ⇒ Object
TODO make strategies directly comparable
87 88 89 |
# File 'lib/database_cleaner/base.rb', line 87 def ==(other) self.orm == other.orm && self.db == other.db && self.strategy.class == other.strategy.class end |
#auto_detected? ⇒ Boolean
82 83 84 |
# File 'lib/database_cleaner/base.rb', line 82 def auto_detected? return true unless @autodetected.nil? end |
#clean ⇒ Object Also known as: clean!
76 77 78 |
# File 'lib/database_cleaner/base.rb', line 76 def clean strategy.clean end |
#clean_with(*args) ⇒ Object Also known as: clean_with!
37 38 39 40 41 |
# File 'lib/database_cleaner/base.rb', line 37 def clean_with(*args) strategy = create_strategy(*args) strategy.clean strategy end |
#create_strategy(*args) ⇒ Object
32 33 34 35 |
# File 'lib/database_cleaner/base.rb', line 32 def create_strategy(*args) strategy, *strategy_args = args orm_strategy(strategy).new(*strategy_args) end |
#db ⇒ Object
28 29 30 |
# File 'lib/database_cleaner/base.rb', line 28 def db @db || :default end |
#db=(desired_db) ⇒ Object
15 16 17 18 |
# File 'lib/database_cleaner/base.rb', line 15 def db=(desired_db) self.strategy_db = desired_db @db = desired_db end |
#orm ⇒ Object
68 69 70 |
# File 'lib/database_cleaner/base.rb', line 68 def orm @orm || autodetect end |
#orm=(desired_orm) ⇒ Object
64 65 66 |
# File 'lib/database_cleaner/base.rb', line 64 def orm=(desired_orm) @orm = desired_orm.to_sym end |
#start ⇒ Object
72 73 74 |
# File 'lib/database_cleaner/base.rb', line 72 def start strategy.start end |
#strategy ⇒ Object
60 61 62 |
# File 'lib/database_cleaner/base.rb', line 60 def strategy @strategy || NullStrategy end |
#strategy=(args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/database_cleaner/base.rb', line 45 def strategy=(args) strategy, *strategy_args = args if strategy.is_a?(Symbol) @strategy = create_strategy(*args) elsif strategy_args.empty? @strategy = strategy else raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params." end self.strategy_db = self.db @strategy end |
#strategy_db=(desired_db) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/database_cleaner/base.rb', line 20 def strategy_db=(desired_db) if strategy.respond_to? :db= strategy.db = desired_db elsif desired_db!= :default raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database" end end |