Module: DatabaseCleaner::ActiveRecord::Base
- Includes:
- Generic::Base
- Included in:
- Transaction, Truncation
- Defined in:
- lib/database_cleaner/active_record/base.rb
Instance Attribute Summary collapse
-
#connection_hash ⇒ Object
Returns the value of attribute connection_hash.
Instance Method Summary collapse
- #connection_klass ⇒ Object
- #create_connection_klass ⇒ Object
- #db ⇒ Object
- #db=(desired_db) ⇒ Object
- #load_config ⇒ Object
Methods included from Generic::Base
Instance Attribute Details
#connection_hash ⇒ Object
Returns the value of attribute connection_hash.
23 24 25 |
# File 'lib/database_cleaner/active_record/base.rb', line 23 def connection_hash @connection_hash end |
Instance Method Details
#connection_klass ⇒ Object
45 46 47 48 49 50 |
# File 'lib/database_cleaner/active_record/base.rb', line 45 def connection_klass return ::ActiveRecord::Base if connection_hash.nil? klass = create_connection_klass klass.send :establish_connection, connection_hash klass end |
#create_connection_klass ⇒ Object
41 42 43 |
# File 'lib/database_cleaner/active_record/base.rb', line 41 def create_connection_klass Class.new(::ActiveRecord::Base) end |
#db ⇒ Object
30 31 32 |
# File 'lib/database_cleaner/active_record/base.rb', line 30 def db @db || super end |
#db=(desired_db) ⇒ Object
25 26 27 28 |
# File 'lib/database_cleaner/active_record/base.rb', line 25 def db=(desired_db) @db = desired_db load_config end |
#load_config ⇒ Object
34 35 36 37 38 39 |
# File 'lib/database_cleaner/active_record/base.rb', line 34 def load_config if File.file?(ActiveRecord.config_file_location) connection_details = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result) self.connection_hash = connection_details[self.db.to_s] end end |