Class: CouchModel::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_model/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(options = { }) ⇒ Server

Returns a new instance of Server.



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

def initialize(options = { })
  @host = options[:host] || "localhost"
  @port = options[:port] || "5984"
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/couch_model/server.rb', line 17

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

#database_namesObject



29
30
31
# File 'lib/couch_model/server.rb', line 29

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

#informationsObject



21
22
23
# File 'lib/couch_model/server.rb', line 21

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

#statisticsObject



25
26
27
# File 'lib/couch_model/server.rb', line 25

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

#urlObject



38
39
40
# File 'lib/couch_model/server.rb', line 38

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

#uuids(count = 1) ⇒ Object



33
34
35
36
# File 'lib/couch_model/server.rb', line 33

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