Class: QAT::DB::Loader

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/qat/db/loader.rb

Overview

Database connections loader from Hash or configuration files.

Since:

  • 1.1.0

Constant Summary collapse

MANDATORY_KEYS =

Mandatory keys for database configurations

Since:

  • 1.1.0

[:host, :database, :username, :password, :adapter]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns the QAT::DB::Loader connections storage

Parameters:

  • (Hash)

Since:

  • 1.1.0



21
22
23
# File 'lib/qat/db/loader.rb', line 21

def initialize
  reset!
end

Instance Attribute Details

#connectionsObject (readonly)

Since:

  • 1.1.0



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.

Since:

  • 1.1.0



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

Parameters:

  • database (String)

    database identifier

  • properties (Hash)

    database properties

Since:

  • 1.1.0



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

Parameters:

  • file_path (String)

    file containing browser drivers

Since:

  • 1.1.0



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

Since:

  • 1.1.0



25
26
27
# File 'lib/qat/db/loader.rb', line 25

def reset!
  @connections = {}
end