Module: RDBI::DBRC

Defined in:
lib/rdbi-dbrc.rb

Class Method Summary collapse

Class Method Details

.connect(role) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rdbi-dbrc.rb', line 6

def self.connect(role)
  role_data = self.roles[role.to_sym]

  unless role_data
    raise ArgumentError, "role '#{role}' does not exist."
  end

  driver = role_data.delete(:driver)

  RDBI.connect(driver, role_data)
end

.rolesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rdbi-dbrc.rb', line 18

def self.roles
  rcfile = ENV["DBRC"] || File.expand_path(File.join(ENV["HOME"], '.dbrc'))

  # XXX the rc file should only be two levels deep, so instead of mentarbating
  # XXX with recursion, let's just do it the cheap way.

  hash = RDBI::Util.key_hash_as_symbols(YAML.load_file(rcfile))
  hash.each do |key, value|
    hash[key] = RDBI::Util.key_hash_as_symbols(hash[key])
  end

  hash
end