Sha256: 83cdb55e50622081189ae8419acec74329e5c90434046ba504e6c4330f3777dd

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

module CouchRest
  class Server
    attr_accessor :uri, :uuid_batch_count
    def initialize server = 'http://127.0.0.1:5984', uuid_batch_count = 1000
      @uri = server
      @uuid_batch_count = uuid_batch_count
    end
  
    # List all databases on the server
    def databases
      CouchRest.get "#{@uri}/_all_dbs"
    end
  
    # Returns a CouchRest::Database for the given name
    def database name
      CouchRest::Database.new(self, name)
    end
  
    # Creates the database if it doesn't exist
    def database! name
      create_db(name) rescue nil
      database name
    end
  
    # GET the welcome message
    def info
      CouchRest.get "#{@uri}/"
    end

    # Create a database
    def create_db name
      CouchRest.put "#{@uri}/#{name}"
      database name
    end

    # Restart the CouchDB instance
    def restart!
      CouchRest.post "#{@uri}/_restart"
    end

    # Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
    def next_uuid count = @uuid_batch_count
      @uuids ||= []
      if @uuids.empty?
        @uuids = CouchRest.post("#{@uri}/_uuids?count=#{count}")["uuids"]
      end
      @uuids.pop
    end

  end
end

Version data entries

12 entries across 12 versions & 5 rubygems

Version Path
jchris-couchrest-0.12.2 lib/couchrest/core/server.rb
jchris-couchrest-0.12.4 lib/couchrest/core/server.rb
jchris-couchrest-0.12.5 lib/couchrest/core/server.rb
jchris-couchrest-0.12.6 lib/couchrest/core/server.rb
jgre-couchrest-0.12.6 lib/couchrest/core/server.rb
mattly-couchrest-0.12.1 lib/couchrest/core/server.rb
mattly-couchrest-0.12.2 lib/couchrest/core/server.rb
mattly-couchrest-0.12.6 lib/couchrest/core/server.rb
samflores-couchrest-0.12.3.2 lib/couchrest/core/server.rb
samflores-couchrest-0.12.3 lib/couchrest/core/server.rb
couchrest-0.12.4 lib/couchrest/core/server.rb
couchrest-0.12.2 lib/couchrest/core/server.rb