Class: CouchRest::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server = 'http://localhost:5984', uuid_batch_count = 1000) ⇒ Server

Returns a new instance of Server.



4
5
6
7
# File 'lib/couchrest/core/server.rb', line 4

def initialize server = 'http://localhost:5984', uuid_batch_count = 1000
  @uri = server
  @uuid_batch_count = uuid_batch_count
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/couchrest/core/server.rb', line 3

def uri
  @uri
end

#uuid_batch_countObject

Returns the value of attribute uuid_batch_count.



3
4
5
# File 'lib/couchrest/core/server.rb', line 3

def uuid_batch_count
  @uuid_batch_count
end

Instance Method Details

#create_db(name) ⇒ Object

create a database



30
31
32
33
# File 'lib/couchrest/core/server.rb', line 30

def create_db name
  CouchRest.put "#{@uri}/#{name}"
  database name
end

#database(name) ⇒ Object



14
15
16
# File 'lib/couchrest/core/server.rb', line 14

def database name
  CouchRest::Database.new(self, name)
end

#database!(name) ⇒ Object

creates the database if it doesn’t exist



19
20
21
22
# File 'lib/couchrest/core/server.rb', line 19

def database! name
  create_db(name) rescue nil
  database name
end

#databasesObject

list all databases on the server



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

def databases
  CouchRest.get "#{@uri}/_all_dbs"
end

#infoObject

get the welcome message



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

def info
  CouchRest.get "#{@uri}/"
end

#next_uuid(count = @uuid_batch_count) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/couchrest/core/server.rb', line 40

def next_uuid count = @uuid_batch_count
  @uuids ||= []
  if @uuids.empty?
    @uuids = CouchRest.post("#{@uri}/_uuids?count=#{count}")["uuids"]
  end
  @uuids.pop
end

#restart!Object

restart the couchdb instance



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

def restart!
  CouchRest.post "#{@uri}/_restart"
end