Sha256: e75f9670a51043740c5be6e59c6b826aa32808157385bc038c4b6688279471b4

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

module Oci8Simple
  ##
  # 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
  #
  class Config
    USER_DIR = File.join(ENV["HOME"], ".oci8_simple")

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

    def initialize
      load_yaml 
    end

    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oci8_simple-0.9.2 lib/oci8_simple/config.rb
oci8_simple-0.9.1 lib/oci8_simple/config.rb