Class: CouchDB::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/couchdb/server.rb

Overview

The Server class provides methods to retrieve information and statistics of a CouchDB server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil, username = nil, password = nil) ⇒ Server

Returns a new instance of Server.



15
16
17
# File 'lib/couchdb/server.rb', line 15

def initialize(host = nil, port = nil, username = nil, password = nil)
  @host, @port, @username, @password = host, port, username, password
end

Instance Attribute Details

#hostObject



19
20
21
# File 'lib/couchdb/server.rb', line 19

def host
  @host || "localhost"
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/couchdb/server.rb', line 11

def password
  @password
end

#password_saltObject

Returns the value of attribute password_salt.



13
14
15
# File 'lib/couchdb/server.rb', line 13

def password_salt
  @password_salt
end

#portObject



23
24
25
# File 'lib/couchdb/server.rb', line 23

def port
  @port || 5984
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/couchdb/server.rb', line 10

def username
  @username
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/couchdb/server.rb', line 27

def ==(other)
  other.is_a?(self.class) && self.host == other.host && self.port == other.port
end

#authentication_optionsObject



56
57
58
# File 'lib/couchdb/server.rb', line 56

def authentication_options
  self.username && self.password ? { :auth_type => :basic, :username => self.username, :password => self.password } : { }
end

#database_namesObject



39
40
41
# File 'lib/couchdb/server.rb', line 39

def database_names
  Transport::JSON.request :get, url + "/_all_dbs", options
end

#informationObject



31
32
33
# File 'lib/couchdb/server.rb', line 31

def information
  Transport::JSON.request :get, url + "/", options
end

#statisticsObject



35
36
37
# File 'lib/couchdb/server.rb', line 35

def statistics
  Transport::JSON.request :get, url + "/_stats", options
end

#urlObject



52
53
54
# File 'lib/couchdb/server.rb', line 52

def url
  "http://#{self.host}:#{self.port}"
end

#user_databaseObject



48
49
50
# File 'lib/couchdb/server.rb', line 48

def user_database
  @user_database ||= UserDatabase.new self
end

#uuids(count = 1) ⇒ Object



43
44
45
46
# File 'lib/couchdb/server.rb', line 43

def uuids(count = 1)
  response = Transport::JSON.request :get, url + "/_uuids", options.merge(:parameters => { :count => count })
  response["uuids"]
end