require 'rubygems' require 'yaml' require 'json' module Rid CONFIG_FILENAME = ".ridrc" 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