Class: Aqua::Store::CouchDB::Server
Server
Attributes
Instance Attributes
namespace | [R] | public |
Returns the value of attribute namespace. |
---|---|---|---|
uri | [RW] | public |
Sets the attribute uri. |
uuid_batch_count | [RW] | public |
Sets the attribute uuid_batch_count. |
uuids | [RW] | public |
Sets the attribute uuids. |
Constructor Summary
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 |
Public Visibility
Public Instance Method Summary
#database(name) |
Returns a CouchRest::Database for the given name. |
---|---|
#database!(name) |
Creates the database if it doesn’t exist. |
#database_names |
DATABASE MANAGMENT ----------— Lists all database names on the server. |
#databases | |
#delete_all |
Deletes all database with the less exection raising method: database. |
#delete_all! |
Deletes all databases named for this namespace (i. |
#info |
GET the welcome message. |
#load_uuids(count = @uuid_batch_count) | |
#namespace=(name) | |
#next_uuid(count = @uuid_batch_count) |
Retrive an unused UUID from CouchDB. |
#restart! |
Restart the CouchDB instance. |
#uuid_count |
counts the number of uuids available, used by Database to limit bulk save. |
Public Instance Method Details
database
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!
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
DATABASE MANAGMENT ----------— 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
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
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!
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
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
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 |
namespace=
18 19 20 21 22 23 24 |
# File 'lib/aqua/store/couch_db/server.rb', line 18 def namespace=( name ) default = 'aqua' name ||= default name = CouchDB.escape( name ) name = default if name.empty? @namespace = name end |
next_uuid
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!
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
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 |