Class: Sova::Server
- Inherits:
-
Object
- Object
- Sova::Server
- Defined in:
- lib/sova/server.rb
Instance Attribute Summary collapse
-
#available_databases ⇒ Object
Returns the value of attribute available_databases.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
Instance Method Summary collapse
-
#create_db(name) ⇒ Object
Create a database.
-
#database(name) ⇒ Object
Returns a Sova::Database for the given name.
-
#database!(name) ⇒ Object
Creates the database if it doesn’t exist.
-
#databases ⇒ Object
Lists all databases on the server.
-
#info ⇒ Object
GET the welcome message.
-
#initialize(server = 'http://127.0.0.1:5984', uuid_batch_count = 1000) ⇒ Server
constructor
A new instance of Server.
-
#next_uuid(count = @uuid_batch_count) ⇒ Object
Retrive an unused UUID from CouchDB.
-
#restart! ⇒ Object
Restart the CouchDB instance.
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/sova/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_databases ⇒ Object
Returns the value of attribute available_databases.
3 4 5 |
# File 'lib/sova/server.rb', line 3 def available_databases @available_databases end |
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/sova/server.rb', line 3 def uri @uri end |
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
3 4 5 |
# File 'lib/sova/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/sova/server.rb', line 31 def create_db(name) HTTP.put "#{@uri}/#{name}" database(name) end |
#database(name) ⇒ Object
Returns a Sova::Database for the given name
15 16 17 |
# File 'lib/sova/server.rb', line 15 def database(name) Sova::Database.new(self, name) end |
#database!(name) ⇒ Object
Creates the database if it doesn’t exist
20 21 22 23 |
# File 'lib/sova/server.rb', line 20 def database!(name) create_db(name) rescue nil database(name) end |
#databases ⇒ Object
Lists all databases on the server
10 11 12 |
# File 'lib/sova/server.rb', line 10 def databases HTTP.get "#{@uri}/_all_dbs" end |
#info ⇒ Object
GET the welcome message
26 27 28 |
# File 'lib/sova/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/sova/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 |