Object
Checks that a database is set as available
Example:
@couch.available_database?(:default)
# File lib/couchrest/server.rb, line 34 def available_database?(ref_or_name) ref_or_name.is_a?(Symbol) ? available_databases.keys.include?(ref_or_name) : available_databases.values.map{|db| db.name}.include?(ref_or_name) end
Create a database
# File lib/couchrest/server.rb, line 70 def create_db(name) CouchRest.put "#{@uri}/#{name}" database(name) end
Returns a CouchRest::Database for the given name
# File lib/couchrest/server.rb, line 52 def database(name) CouchRest::Database.new(self, name) end
Creates the database if it doesn't exist
# File lib/couchrest/server.rb, line 57 def database!(name) CouchRest.head "#{@uri}/#{name}" # Check if the URL is valid database(name) rescue RestClient::ResourceNotFound # Thrown if the HTTP HEAD fails create_db(name) end
Lists all databases on the server
# File lib/couchrest/server.rb, line 47 def databases CouchRest.get "#{@uri}/_all_dbs" end
# File lib/couchrest/server.rb, line 42 def default_database available_databases[:default] end
# File lib/couchrest/server.rb, line 38 def default_database=(name, create_unless_exists = true) define_available_database(:default, name, create_unless_exists = true) end
Adds a new available database and create it unless it already exists
Example:
@couch = CouchRest::Server.new @couch.define_available_database(:default, "tech-blog")
# File lib/couchrest/server.rb, line 24 def define_available_database(reference, db_name, create_unless_exists = true) available_databases[reference.to_sym] = create_unless_exists ? database!(db_name) : database(db_name) end
GET the welcome message
# File lib/couchrest/server.rb, line 65 def info CouchRest.get "#{@uri}/" end
Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
# File lib/couchrest/server.rb, line 83 def next_uuid(count = @uuid_batch_count) @uuids ||= [] if @uuids.empty? @uuids = CouchRest.get("#{@uri}/_uuids?count=#{count}")["uuids"] end @uuids.pop end
Generated with the Darkfish Rdoc Generator 2.