Class: DatabaseCleaner::Base
- Inherits:
-
Object
- Object
- DatabaseCleaner::Base
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/database_cleaner/base.rb
Instance Attribute Summary collapse
-
#orm ⇒ Object
Returns the value of attribute orm.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#auto_detected? ⇒ Boolean
TODO remove the following methods in 2.0.
- #autodetect_orm ⇒ Object
- #clean! ⇒ Object
- #clean_with(*args) ⇒ Object
- #clean_with! ⇒ Object
- #create_strategy(*args) ⇒ Object
- #db ⇒ Object
- #db=(desired_db) ⇒ Object
-
#initialize(desired_orm = nil, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #set_strategy_db(strategy, desired_db) ⇒ Object
- #strategy ⇒ Object
- #strategy=(args) ⇒ Object
-
#strategy_db=(desired_db) ⇒ Object
TODO privatize the following methods in 2.0.
Constructor Details
#initialize(desired_orm = nil, opts = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 |
# File 'lib/database_cleaner/base.rb', line 16 def initialize(desired_orm = nil, opts = {}) @orm_autodetector = ORMAutodetector.new self.orm = desired_orm self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model) self.strategy = orm_module && orm_module.default_strategy Safeguard.new.run end |
Instance Attribute Details
#orm ⇒ Object
Returns the value of attribute orm.
49 50 51 |
# File 'lib/database_cleaner/base.rb', line 49 def orm @orm end |
Instance Method Details
#<=>(other) ⇒ Object
12 13 14 |
# File 'lib/database_cleaner/base.rb', line 12 def <=>(other) [orm, db] <=> [other.orm, other.db] end |
#auto_detected? ⇒ Boolean
TODO remove the following methods in 2.0
68 69 70 71 |
# File 'lib/database_cleaner/base.rb', line 68 def auto_detected? DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].auto_detected?` is deprecated, and will be removed in database_cleaner 2.0 with no replacement." @orm_autodetector.autodetected? end |
#autodetect_orm ⇒ Object
73 74 75 76 |
# File 'lib/database_cleaner/base.rb', line 73 def autodetect_orm DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].autodetect_orm` is deprecated, and will be removed in database_cleaner 2.0 with no replacement." @orm_autodetector.orm end |
#clean! ⇒ Object
78 79 80 81 |
# File 'lib/database_cleaner/base.rb', line 78 def clean! DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean instead." clean end |
#clean_with(*args) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/database_cleaner/base.rb', line 59 def clean_with(*args) strategy = create_strategy(*args) set_strategy_db strategy, db strategy.clean strategy end |
#clean_with! ⇒ Object
83 84 85 86 |
# File 'lib/database_cleaner/base.rb', line 83 def clean_with! DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].clean_with instead." clean_with end |
#create_strategy(*args) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/database_cleaner/base.rb', line 108 def create_strategy(*args) if called_externally?(caller) DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].create_strategy` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].strategy=` instead." end 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
24 25 26 |
# File 'lib/database_cleaner/base.rb', line 24 def db=(desired_db) @db = self.strategy_db = desired_db end |
#set_strategy_db(strategy, desired_db) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/database_cleaner/base.rb', line 97 def set_strategy_db(strategy, desired_db) if called_externally?(caller) DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].set_strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead." end 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 |
#strategy ⇒ Object
45 46 47 |
# File 'lib/database_cleaner/base.rb', line 45 def strategy @strategy ||= NullStrategy.new end |
#strategy=(args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/database_cleaner/base.rb', line 32 def strategy=(args) strategy, *strategy_args = args @strategy = if strategy.is_a?(Symbol) create_strategy(*args) elsif strategy_args.empty? strategy else raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params." end set_strategy_db @strategy, db end |
#strategy_db=(desired_db) ⇒ Object
TODO privatize the following methods in 2.0
90 91 92 93 94 95 |
# File 'lib/database_cleaner/base.rb', line 90 def strategy_db=(desired_db) if called_externally?(caller) DatabaseCleaner.deprecate "Calling `DatabaseCleaner[...].strategy_db=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner[...].db=` instead." end set_strategy_db(strategy, desired_db) end |