Module: CouchRest
- Extended by:
- RestAPI
- Defined in:
- lib/couchrest.rb,
lib/couchrest/design.rb,
lib/couchrest/server.rb,
lib/couchrest/database.rb,
lib/couchrest/document.rb,
lib/couchrest/response.rb,
lib/couchrest/helper/pager.rb,
lib/couchrest/commands/push.rb,
lib/couchrest/helper/upgrade.rb,
lib/couchrest/helper/streamer.rb,
lib/couchrest/commands/generate.rb,
lib/couchrest/helper/attachments.rb,
lib/couchrest/middlewares/logger.rb
Overview
USAGE
in your rack.rb file require this file and then:
couch = CouchRest.new LOG_DB = couch.database!(‘couchrest-logger’) use CouchRest::Logger, LOG_DB
Note: to require just this middleware, if you have the gem installed do: require ‘couchrest/middlewares/logger’
For log processing examples, see examples at the bottom of this file
Defined Under Namespace
Modules: Attachments, Commands Classes: Database, Design, Document, ExtendedDocument, Logger, Pager, Response, Server, Streamer, Upgrade
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
- .database(url) ⇒ Object
-
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created.
-
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
- .paramify_url(url, params = {}) ⇒ Object
- .parse(url) ⇒ Object
-
.proxy(url) ⇒ Object
set proxy to use.
Methods included from RestAPI
Class Method Details
.database(url) ⇒ Object
108 109 110 111 112 |
# File 'lib/couchrest.rb', line 108 def database url parsed = parse url cr = CouchRest.new(parsed[:host]) cr.database(parsed[:database]) end |
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created
102 103 104 105 106 |
# File 'lib/couchrest.rb', line 102 def database! url parsed = parse url cr = CouchRest.new(parsed[:host]) cr.database!(parsed[:database]) end |
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
56 57 58 |
# File 'lib/couchrest.rb', line 56 def new(*opts) Server.new(*opts) end |
.paramify_url(url, params = {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/couchrest.rb', line 114 def paramify_url url, params = {} if params && !params.empty? query = params.collect do |k,v| v = v.to_json if %w{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") url = "#{url}?#{query}" end url end |
.parse(url) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/couchrest.rb', line 60 def parse url case url when /^(https?:\/\/)(.*)\/(.*)\/(.*)/ scheme = $1 host = $2 db = $3 docid = $4 when /^(https?:\/\/)(.*)\/(.*)/ scheme = $1 host = $2 db = $3 when /^(https?:\/\/)(.*)/ scheme = $1 host = $2 when /(.*)\/(.*)\/(.*)/ host = $1 db = $2 docid = $3 when /(.*)\/(.*)/ host = $1 db = $2 else db = url end db = nil if db && db.empty? { :host => (scheme || "http://") + (host || "127.0.0.1:5984"), :database => db, :doc => docid } end |
.proxy(url) ⇒ Object
set proxy to use
95 96 97 |
# File 'lib/couchrest.rb', line 95 def proxy url RestClient.proxy = url end |