Sha256: 8a97122c8f9f4c2b7ead149529a6eb8cd529c5b4b6b0826a2a367d442a47958a

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

require 'rubygems'
require 'yaml'
require 'json'

module Couch
  CONFIG_FILENAME = ".couchrc"

  def self.root
    @root ||= find_root
  end

  def self.database
    @database ||= config["database"]
  end

  def self.id
    @id ||= File.read(File.join(root, '_id')).strip
  end

  def self.rev
    @rev ||= File.read(File.join(root, '_rev')).strip rescue nil
  end

  private

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

  def self.config_file
    File.join root, CONFIG_FILENAME
  end

  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

1 entries across 1 versions & 1 rubygems

Version Path
couch-0.2.0 lib/couch.rb