Class: Oci8Simple::Config
- Inherits:
-
Object
- Object
- Oci8Simple::Config
- 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
- #[](key) ⇒ Object
- #database_yaml_path ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_yaml ⇒ Object
Constructor Details
#initialize ⇒ Config
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_path ⇒ Object
19 20 21 22 23 24 25 26 27 |
# 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_yaml ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/oci8_simple/config.rb', line 29 def load_yaml file = database_yaml_path begin @raw_config = YAML.load_file(file) rescue Errno::ENOENT => e raise ConfigError.new <<-ERR File #{file} doesn't exist - use the following template: environment: database: 192.168.1.3:1521/sid username: foo_user password: foobar ERR end end |