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
When included, provide the owner with an attributes hash and accessors that forward calls to it.
Provides the basic functionality of Hash without actually being a Hash using Ruby's standard Forwardable module.
Copyright (c) 2006-2009 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Extracted From github.com/rails/rails/commit/971e2438d98326c994ec6d3ef8e37b7e868ed6e2
Provides basic functions for controlling documents returned from the CouchDB database and provides methods to act as a wrapper around a Hash of @_attributes.
The idea is to provide the basic functionality of a Hash, just enought to support the needs of CouchRest, but not inherit all of the functionality found in a basic Hash.
A Response is similar to Rails' HashWithIndifferentAccess as all requests will convert the keys into Symbols and be stored in the master hash as such.
# File lib/couchrest.rb, line 105 def database url parsed = parse url cr = CouchRest.new(parsed[:host]) cr.database(parsed[:database]) end
ensure that a database exists creates it if it isn't already there returns it after it's been created
# File lib/couchrest.rb, line 99 def database! url parsed = parse url cr = CouchRest.new(parsed[:host]) cr.database!(parsed[:database]) end
# File lib/couchrest.rb, line 111 def paramify_url url, params = {} if params && !params.empty? query = params.collect do |k,v| v = MultiJson.encode(v) if %{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") url = "#{url}?#{query}" end url end
# File lib/couchrest.rb, line 57 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
Generated with the Darkfish Rdoc Generator 2.