Module: Merb::RelaxDB

Defined in:
lib/merb_relaxdb/connection.rb

Class Method Summary collapse

Class Method Details

.config_fileObject



6
# File 'lib/merb_relaxdb/connection.rb', line 6

def config_file() Merb.dir_for(:config) / "couchdb.yml" end

.configure_dbObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/merb_relaxdb/connection.rb', line 21

def configure_db
  if File.exists?(config_file)        
    full_config = Erubis.load_yaml_file(config_file)
    config = full_config[Merb.environment.to_sym]
    config[:logger] = Merb.logger
    ::RelaxDB.configure(config)
    ::RelaxDB.db.name = config[:db]
  else
    copy_sample_config
    Merb.logger.error! "No couchdb.yml file found in #{Merb.root}/config."
    Merb.logger.error! "A sample file was created called couchdb.yml.sample for you to copy and edit."
    exit(1)
  end          
end

.connectObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/merb_relaxdb/connection.rb', line 10

def connect
  begin
    configure_db
    Merb.logger.info "RelaxDB: #{::RelaxDB.db.uri}/_design/#{::RelaxDB.dd}"
  rescue => e
    uri = ::RelaxDB.db ? ::RelaxDB.db.uri : "<initialisation error>"
    Merb.logger.fatal "RelaxDB could not connect to CouchDB at #{uri} \n\tRoot cause:#{e}\n#{e.backtrace.join("\n")}"
    exit(1)
  end
end

.copy_sample_configObject



36
37
38
# File 'lib/merb_relaxdb/connection.rb', line 36

def copy_sample_config
  FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
end

.sample_destObject



7
# File 'lib/merb_relaxdb/connection.rb', line 7

def sample_dest() Merb.dir_for(:config) / "couchdb.yml.sample" end

.sample_sourceObject



8
# File 'lib/merb_relaxdb/connection.rb', line 8

def sample_source() File.dirname(__FILE__) / "couchdb.yml.sample" end