Class: Aqua::Store::CouchDB::Server
- Inherits:
-
Object
- Object
- Aqua::Store::CouchDB::Server
- Defined in:
- lib/aqua/store/couch_db/server.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
-
#uuids ⇒ Object
Returns the value of attribute uuids.
Instance Method Summary collapse
-
#database(name) ⇒ Object
Returns a CouchRest::Database for the given name.
-
#database!(name) ⇒ Object
Creates the database if it doesn’t exist.
-
#database_names ⇒ Object
Lists all database names on the server.
- #databases ⇒ Object
-
#delete_all ⇒ Object
Deletes all database with the less exection raising method: database.delete.
-
#delete_all! ⇒ Object
Deletes all databases named for this namespace (i.e. this server) Use with caution …
-
#info ⇒ Object
GET the welcome message.
-
#initialize(opts = {}) ⇒ Server
constructor
A new instance of Server.
- #load_uuids(count = @uuid_batch_count) ⇒ Object
-
#next_uuid(count = @uuid_batch_count) ⇒ Object
Retrive an unused UUID from CouchDB.
-
#restart! ⇒ Object
Restart the CouchDB instance.
-
#uuid_count ⇒ Object
counts the number of uuids available, used by Database to limit bulk save.
Constructor Details
#initialize(opts = {}) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 |
# File 'lib/aqua/store/couch_db/server.rb', line 11 def initialize(opts={}) opts = Mash.new(opts) unless opts.empty? self.uri = opts[:server] || 'http://127.0.0.1:5984' self.uuid_batch_count = opts[:uuid_batch_count] || 1000 self.namespace = opts[:namespace].to_s end |
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/aqua/store/couch_db/server.rb', line 9 def namespace @namespace end |
#uri ⇒ Object
Returns the value of attribute uri.
8 9 10 |
# File 'lib/aqua/store/couch_db/server.rb', line 8 def uri @uri end |
#uuid_batch_count ⇒ Object
Returns the value of attribute uuid_batch_count.
8 9 10 |
# File 'lib/aqua/store/couch_db/server.rb', line 8 def uuid_batch_count @uuid_batch_count end |
#uuids ⇒ Object
Returns the value of attribute uuids.
8 9 10 |
# File 'lib/aqua/store/couch_db/server.rb', line 8 def uuids @uuids end |
Instance Method Details
#database(name) ⇒ Object
Returns a CouchRest::Database for the given name
56 57 58 59 |
# File 'lib/aqua/store/couch_db/server.rb', line 56 def database(name) db = Database.new( name, :server => self ) db.exists? ? db : nil end |
#database!(name) ⇒ Object
Creates the database if it doesn’t exist
62 63 64 |
# File 'lib/aqua/store/couch_db/server.rb', line 62 def database!(name) Database.create( name, :server => self ) end |
#database_names ⇒ Object
Lists all database names on the server
29 30 31 32 |
# File 'lib/aqua/store/couch_db/server.rb', line 29 def database_names dbs = CouchDB.get( "#{@uri}/_all_dbs" ) dbs.select{|name| name.match(/\A#{namespace}_?/)} end |
#databases ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/aqua/store/couch_db/server.rb', line 34 def databases dbs = [] database_names.each do |db_name| dbs << Database.new( db_name.gsub(/\A#{namespace}_|\A#{namespace}\z/, '') , :server => self ) end dbs end |
#delete_all ⇒ Object
Deletes all database with the less exection raising method: database.delete. This will only raise errors related to request problems, and not errors related to the database not being found for deletion.
51 52 53 |
# File 'lib/aqua/store/couch_db/server.rb', line 51 def delete_all databases.each{ |db| db.delete } end |
#delete_all! ⇒ Object
Deletes all databases named for this namespace (i.e. this server) Use with caution … it is a permanent and undoable change
44 45 46 |
# File 'lib/aqua/store/couch_db/server.rb', line 44 def delete_all! databases.each{ |db| db.delete! } end |
#info ⇒ Object
GET the welcome message
67 68 69 |
# File 'lib/aqua/store/couch_db/server.rb', line 67 def info CouchDB.get "#{uri}/" end |
#load_uuids(count = @uuid_batch_count) ⇒ Object
95 96 97 |
# File 'lib/aqua/store/couch_db/server.rb', line 95 def load_uuids( count=@uuid_batch_count ) @uuids = CouchDB.get("#{@uri}/_uuids?count=#{count}")["uuids"] end |
#next_uuid(count = @uuid_batch_count) ⇒ Object
Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
87 88 89 90 91 92 93 |
# File 'lib/aqua/store/couch_db/server.rb', line 87 def next_uuid(count = @uuid_batch_count) @uuids ||= [] if uuids.empty? load_uuids(count) end uuids.pop end |
#restart! ⇒ Object
Restart the CouchDB instance
72 73 74 |
# File 'lib/aqua/store/couch_db/server.rb', line 72 def restart! CouchDB.post "#{uri}/_restart" end |
#uuid_count ⇒ Object
counts the number of uuids available, used by Database to limit bulk save
77 78 79 80 81 82 83 84 |
# File 'lib/aqua/store/couch_db/server.rb', line 77 def uuid_count if uuids uuids.size else load_uuids uuid_batch_count end end |