Class: Oci8Simple::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/oci8_simple/config.rb

Overview

Config will look in three places for your database.yml file. Here is the order:

Dir.pwd + database.yml
Dir.pwd + config/database.yml
~/.oci8_simple/database.yml

Constant Summary collapse

USER_DIR =
File.join(ENV["HOME"], ".oci8_simple")

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
# File 'lib/oci8_simple/config.rb', line 15

def initialize
  load_yaml 
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/oci8_simple/config.rb', line 11

def [](key)
  @raw_config[key]
end

#database_yaml_pathObject



19
20
21
22
23
24
25
# File 'lib/oci8_simple/config.rb', line 19

def database_yaml_path
  path = File.join(Dir.pwd, "database.yml")
  return path if File.exists?(path)
  path = File.join(Dir.pwd, "config", "database.yml")
  return path if File.exists?(path)
  File.join(USER_DIR, "database.yml")
end

#load_yamlObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/oci8_simple/config.rb', line 27

def load_yaml
  begin
    @raw_config = YAML.load_file(database_yaml_path)
  rescue Errno::ENOENT => e
    raise ConfigError.new <<-ERR
File #{CONFIG_FILE} doesn't exist - use the following template:

environment:
  database: 192.168.1.3:1521/sid
  username: foo_user
  password: foobar

ERR
  end
end