Sha256: e49b38e21c2e39896343ddce063507f1a5edc79a3768efc2b411ee2c644c402e

Contents?: true

Size: 562 Bytes

Versions: 5

Compression:

Stored size: 562 Bytes

Contents

require 'yaml'

module Couch
  CONFIG_FILENAME = ".couchrc"

  def self.root
    @root ||= find_root
  end

  def self.database
    config["database"]
  end

  def self.config
    @config ||= YAML.load(File.open config_file)
  end

  def self.config_file
    File.join root, CONFIG_FILENAME
  end

  private

  def self.find_root
    cwd = Dir.pwd
    return cwd if File.exists?(File.join(cwd, CONFIG_FILENAME))
    Dir.chdir("..") do
      find_root unless cwd == Dir.pwd
    end
  rescue SystemCallError
    # could not chdir, no problem just return
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
couch-0.1.0 lib/couch.rb
couch-0.0.4 lib/couch.rb
couch-0.0.3 lib/couch.rb
couch-0.0.2 lib/couch.rb
couch-0.0.1 lib/couch.rb