Class: QAT::DB::Loader
- Inherits:
-
Object
- Object
- QAT::DB::Loader
- Includes:
- Singleton
- Defined in:
- lib/qat/db/loader.rb
Overview
Database connections loader from Hash or configuration files.
Constant Summary collapse
- MANDATORY_KEYS =
Mandatory keys for database configurations
[:host, :database, :username, :password, :adapter]
Instance Attribute Summary collapse
- #connections ⇒ Object readonly
Class Method Summary collapse
- .method_missing(*args) ⇒ Object private
Instance Method Summary collapse
-
#initialize ⇒ Loader
constructor
Returns the QAT::DB::Loader connections storage.
-
#load_db(database, properties) ⇒ Object
Loads a database connection.
-
#load_file(file_path) ⇒ Object
Loads databases connections from a YAML file.
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Loader
Returns the QAT::DB::Loader connections storage
21 22 23 |
# File 'lib/qat/db/loader.rb', line 21 def initialize reset! end |
Instance Attribute Details
#connections ⇒ Object (readonly)
12 13 14 |
# File 'lib/qat/db/loader.rb', line 12 def connections @connections end |
Class Method Details
.method_missing(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/qat/db/loader.rb', line 31 def method_missing(*args) self.instance.send(*args) end |
Instance Method Details
#load_db(database, properties) ⇒ Object
Loads a database connection
47 48 49 |
# File 'lib/qat/db/loader.rb', line 47 def load_db(database, properties) connections.merge!({ database.to_sym => connection(properties) }) end |
#load_file(file_path) ⇒ Object
Loads databases connections from a YAML file
38 39 40 41 |
# File 'lib/qat/db/loader.rb', line 38 def load_file(file_path) databases = YAML::load(::File.read(file_path)) || {} databases.each { |database, properties| load_db(database, properties) } end |
#reset! ⇒ Object
25 26 27 |
# File 'lib/qat/db/loader.rb', line 25 def reset! @connections = {} end |