Class: CouchDB::Server

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 5984) ⇒ Server

Returns a new instance of Server.



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

def initialize(host = "localhost", port = 5984)
  @host, @port = host, port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/couchdb/server.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#==(other) ⇒ Object



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

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

#database_namesObject



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

def database_names
  Transport::JSON.request :get, url + "/_all_dbs", :expected_status_code => 200
end

#informationObject



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

def information
  Transport::JSON.request :get, url + "/", :expected_status_code => 200
end

#statisticsObject



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

def statistics
  Transport::JSON.request :get, url + "/_stats", :expected_status_code => 200
end

#urlObject



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

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

#uuids(count = 1) ⇒ Object



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

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