Module: UseDbPlugin
- Included in:
- UseDbTest
- Defined in:
- lib/use_db/use_db_plugin.rb
Defined Under Namespace
Modules: ClassMixin
Constant Summary collapse
- @@use_dbs =
options can have one or the other of the following options:
:prefix - Specify the prefix to append to the RAILS_ENV when finding the adapter secification in database.yml :suffix - Just like :prefix, only contactentated
OR
:adapter :host :username :password
… etc … same as the options in establish_connection
Set the following to true in your test environment to enable extended debugging printing during testing … UseDbPlugin.debug_print = true
[ActiveRecord::Base]
- @@debug_print =
false
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all_use_dbs ⇒ Object
29 30 31 |
# File 'lib/use_db/use_db_plugin.rb', line 29 def self.all_use_dbs return @@use_dbs end |
.debug_print ⇒ Object
33 34 35 |
# File 'lib/use_db/use_db_plugin.rb', line 33 def self.debug_print return @@debug_print end |
.debug_print=(newval) ⇒ Object
37 38 39 |
# File 'lib/use_db/use_db_plugin.rb', line 37 def self.debug_print=(newval) @@debug_print = newval end |
Instance Method Details
#get_use_db_conn_spec(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/use_db/use_db_plugin.rb', line 47 def get_use_db_conn_spec() .symbolize_keys! # without the bang, this was pointless suffix = .delete(:suffix) prefix = .delete(:prefix) rails_env = .delete(:rails_env) || RAILS_ENV if ([:adapter]) return else str = "#{prefix}#{rails_env}#{suffix}" connections = ActiveRecord::Base.configurations raise "Cannot find database specification. Configuration '#{str}' expected in config/database.yml" if (connections[str].nil?) return connections[str] end end |
#use_db(options) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/use_db/use_db_plugin.rb', line 20 def use_db() = .dup conn_spec = get_use_db_conn_spec() puts "Establishing connecting on behalf of #{self.to_s} to #{conn_spec.inspect}" if UseDbPlugin.debug_print establish_connection(conn_spec) extend ClassMixin @@use_dbs << self unless @@use_dbs.include?(self) || self.to_s.starts_with?("TestModel") end |