Class: Sovaa::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Server.



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

def initialize(server = 'http://127.0.0.1:5984', uuid_batch_count = 1000)
  @uri = server
  @uuid_batch_count = uuid_batch_count
end

Instance Attribute Details

#available_databasesObject

Returns the value of attribute available_databases.



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

def available_databases
  @available_databases
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

#uuid_batch_countObject

Returns the value of attribute uuid_batch_count.



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

def uuid_batch_count
  @uuid_batch_count
end

Instance Method Details

#create_db(name) ⇒ Object

Create a database



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

def create_db(name)
  HTTP.put "#{@uri}/#{name}"
  database(name)
end

#database(name) ⇒ Object

Returns a Sovaa::Database for the given name



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

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

#database!(name) ⇒ Object

Creates the database if it doesn’t exist



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

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

#databasesObject

Lists all databases on the server



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

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

#infoObject

GET the welcome message



26
27
28
# File 'lib/sovaa/server.rb', line 26

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

#next_uuid(count = @uuid_batch_count) ⇒ Object

Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.



42
43
44
45
46
47
48
# File 'lib/sovaa/server.rb', line 42

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

#restart!Object

Restart the CouchDB instance



37
38
39
# File 'lib/sovaa/server.rb', line 37

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