polished documentation
This commit is contained in:
parent
26c4db7fc6
commit
b3b58ffa83
|
@ -24,6 +24,7 @@ $:.unshift File.dirname(__FILE__) unless
|
||||||
|
|
||||||
require 'couchrest/monkeypatches'
|
require 'couchrest/monkeypatches'
|
||||||
|
|
||||||
|
# = CouchDB, close to the metal
|
||||||
module CouchRest
|
module CouchRest
|
||||||
autoload :Server, 'couchrest/core/server'
|
autoload :Server, 'couchrest/core/server'
|
||||||
autoload :Database, 'couchrest/core/database'
|
autoload :Database, 'couchrest/core/database'
|
||||||
|
|
|
@ -5,6 +5,12 @@ module CouchRest
|
||||||
class Database
|
class Database
|
||||||
attr_reader :server, :host, :name, :root
|
attr_reader :server, :host, :name, :root
|
||||||
|
|
||||||
|
# Create a CouchRest::Database adapter for the supplied CouchRest::Server and database name.
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# server<CouchRest::Server>:: database host
|
||||||
|
# name<String>:: database name
|
||||||
|
#
|
||||||
def initialize server, name
|
def initialize server, name
|
||||||
@name = name
|
@name = name
|
||||||
@server = server
|
@server = server
|
||||||
|
@ -12,6 +18,7 @@ module CouchRest
|
||||||
@root = "#{host}/#{name}"
|
@root = "#{host}/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the database's uri
|
||||||
def to_s
|
def to_s
|
||||||
@root
|
@root
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,7 +114,7 @@ module CouchRest
|
||||||
end
|
end
|
||||||
end # module InstanceMethods
|
end # module InstanceMethods
|
||||||
|
|
||||||
# these show up as class methods on models that include CouchRest::Model
|
# Class methods for models that include CouchRest::Model
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# override the CouchRest::Model-wide default_database
|
# override the CouchRest::Model-wide default_database
|
||||||
def use_database db
|
def use_database db
|
||||||
|
|
|
@ -6,37 +6,39 @@ module CouchRest
|
||||||
@uuid_batch_count = uuid_batch_count
|
@uuid_batch_count = uuid_batch_count
|
||||||
end
|
end
|
||||||
|
|
||||||
# list all databases on the server
|
# List all databases on the server
|
||||||
def databases
|
def databases
|
||||||
CouchRest.get "#{@uri}/_all_dbs"
|
CouchRest.get "#{@uri}/_all_dbs"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a CouchRest::Database for the given name
|
||||||
def database name
|
def database name
|
||||||
CouchRest::Database.new(self, name)
|
CouchRest::Database.new(self, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# creates the database if it doesn't exist
|
# Creates the database if it doesn't exist
|
||||||
def database! name
|
def database! name
|
||||||
create_db(name) rescue nil
|
create_db(name) rescue nil
|
||||||
database name
|
database name
|
||||||
end
|
end
|
||||||
|
|
||||||
# get the welcome message
|
# GET the welcome message
|
||||||
def info
|
def info
|
||||||
CouchRest.get "#{@uri}/"
|
CouchRest.get "#{@uri}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
# create a database
|
# Create a database
|
||||||
def create_db name
|
def create_db name
|
||||||
CouchRest.put "#{@uri}/#{name}"
|
CouchRest.put "#{@uri}/#{name}"
|
||||||
database name
|
database name
|
||||||
end
|
end
|
||||||
|
|
||||||
# restart the couchdb instance
|
# Restart the CouchDB instance
|
||||||
def restart!
|
def restart!
|
||||||
CouchRest.post "#{@uri}/_restart"
|
CouchRest.post "#{@uri}/_restart"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
|
||||||
def next_uuid count = @uuid_batch_count
|
def next_uuid count = @uuid_batch_count
|
||||||
@uuids ||= []
|
@uuids ||= []
|
||||||
if @uuids.empty?
|
if @uuids.empty?
|
||||||
|
|
|
@ -5,6 +5,7 @@ module CouchRest
|
||||||
@db = db
|
@db = db
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Stream a view, yielding one row at a time. Shells out to <tt>curl</tt> to keep RAM usage low when you have millions of rows.
|
||||||
def view name, params = nil
|
def view name, params = nil
|
||||||
urlst = /^_/.match(name) ? "#{@db.root}/#{name}" : "#{@db.root}/_view/#{name}"
|
urlst = /^_/.match(name) ? "#{@db.root}/#{name}" : "#{@db.root}/_view/#{name}"
|
||||||
url = CouchRest.paramify_url urlst, params
|
url = CouchRest.paramify_url urlst, params
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
|
# This file must be loaded after the JSON gem and any other library that beats up the Time class.
|
||||||
# this file must be loaded after the JSON gem
|
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
# This date format sorts lexicographically
|
# This date format sorts lexicographically
|
||||||
# and is compatible with Javascript's new Date(time_string) constructor.
|
# and is compatible with Javascript's <tt>new Date(time_string)</tt> constructor.
|
||||||
# Note this this format stores all dates in UTC so that collation
|
# Note this this format stores all dates in UTC so that collation
|
||||||
# order is preserved. (There's no longer a need to set ENV['TZ'] = 'UTC'
|
# order is preserved. (There's no longer a need to set <tt>ENV['TZ'] = 'UTC'</tt>
|
||||||
# in your application.)
|
# in your application.)
|
||||||
|
|
||||||
def to_json(options = nil)
|
def to_json(options = nil)
|
||||||
|
|
Loading…
Reference in a new issue