Class: DanarchyCouchDB::ConfigManager::CouchDB

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_couchdb/config_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(account) ⇒ CouchDB

Returns a new instance of CouchDB.



4
5
6
# File 'lib/danarchy_couchdb/config_manager.rb', line 4

def initialize()
  @account = 
end

Instance Method Details

#new_cdb_connectionObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/danarchy_couchdb/config_manager.rb', line 8

def new_cdb_connection
  if @account[:couchdb]
    print "A CouchDB connection already exists. Should we overwrite it? (Y/n): "
    answer = gets.chomp
    if answer =~ /^n(o)?$/i
      puts "Keeping existing CouchDB Connection."
      return @account
    end
  elsif answer =~ /^y(es)?$/i
    puts "Removing existing CouchDB connection."
    @account.delete(:couchdb)
  end

  print "CouchDB Hostname: "
  hostname = gets.chomp
  print 'CouchDB Username: '
  username = gets.chomp
  print 'CouchDB Password: '
  password = gets.chomp
  print 'CouchDB Database: '
  database = gets.chomp
  print 'Enable SSL? (Y/n): '
  ssl  = gets.chomp
  port = nil

  if ssl =~ /^y(es)?$/i || ssl.empty?
    ssl = true
    port = '6984'
  else
    ssl = false
    port = '5984'
  end
  
  add_couchdb(@account, hostname, username, password, database, port, ssl)
  @account
end

#verify_connection(couchdb) ⇒ Object



45
46
47
48
# File 'lib/danarchy_couchdb/config_manager.rb', line 45

def verify_connection(couchdb)
  cdb = DanarchyCouchDB::Connection.new(couchdb)
  cdb.get('')
end