From 711fdc1ca6e165b242c10895d43d8a298fcd198f Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Thu, 11 Sep 2008 21:25:51 -0700 Subject: [PATCH] all specs pass with the new layout --- lib/couchrest.rb | 26 ++++++++++++++++++++++++-- lib/couchrest/core/server.rb | 19 ------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/couchrest.rb b/lib/couchrest.rb index 0ee562a..2f016b3 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -17,13 +17,35 @@ module CouchRest autoload :Streamer, 'couchrest/helper/streamer' # The CouchRest module methods handle the basic JSON serialization - # and deserialization, as well as query parameters. + # and deserialization, as well as query parameters. The module also includes + # some helpers for tasks like instantiating a new Database or Server instance. class << self - + + # todo, make this parse the url and instantiate a Server or Database instance + # depending on the specificity. def new(*opts) Server.new(*opts) end + # ensure that a database exists + # creates it if it isn't already there + # returns it after it's been created + def database! url + uri = URI.parse url + path = uri.path + uri.path = '' + cr = CouchRest.new(uri.to_s) + cr.database!(path) + end + + def database url + uri = URI.parse url + path = uri.path + uri.path = '' + cr = CouchRest.new(uri.to_s) + cr.database(path) + end + def put uri, doc = nil payload = doc.to_json if doc JSON.parse(RestClient.put(uri, payload)) diff --git a/lib/couchrest/core/server.rb b/lib/couchrest/core/server.rb index 7365277..0091041 100644 --- a/lib/couchrest/core/server.rb +++ b/lib/couchrest/core/server.rb @@ -6,25 +6,6 @@ module CouchRest @uuid_batch_count = uuid_batch_count end - # ensure that a database exists - # creates it if it isn't already there - # returns it after it's been created - def self.database! url - uri = URI.parse url - path = uri.path - uri.path = '' - cr = CouchRest.new(uri.to_s) - cr.database!(path) - end - - def self.database url - uri = URI.parse url - path = uri.path - uri.path = '' - cr = CouchRest.new(uri.to_s) - cr.database(path) - end - # list all databases on the server def databases CouchRest.get "#{@uri}/_all_dbs"