Class: CouchRest::Server
- Inherits:
-
Object
- Object
- CouchRest::Server
- Defined in:
- lib/couchrest/core/server.rb
Instance Attribute Summary collapse
-
#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 CouchRest::Database for the given name.
-
#database!(name) ⇒ Object
Creates the database if it doesn’t exist.
-
#databases ⇒ Object
List all databases on the server.
-
#info ⇒ Object
GET the welcome message.
-
#initialize(server = 'http://localhost: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://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
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/couchrest/core/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/couchrest/core/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/couchrest/core/server.rb', line 31 def create_db name CouchRest.put "#{@uri}/#{name}" database name end |
#database(name) ⇒ Object
Returns a CouchRest::Database for the given name
15 16 17 |
# File 'lib/couchrest/core/server.rb', line 15 def database name CouchRest::Database.new(self, name) end |
#database!(name) ⇒ Object
Creates the database if it doesn’t exist
20 21 22 23 |
# File 'lib/couchrest/core/server.rb', line 20 def database! name create_db(name) rescue nil database name end |
#databases ⇒ Object
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 |
#info ⇒ Object
GET the welcome message
26 27 28 |
# File 'lib/couchrest/core/server.rb', line 26 def info CouchRest.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/couchrest/core/server.rb', line 42 def next_uuid count = @uuid_batch_count @uuids ||= [] if @uuids.empty? @uuids = CouchRest.post("#{@uri}/_uuids?count=#{count}")["uuids"] end @uuids.pop end |