Module: CouchRest
- Extended by:
- RestAPI
- Defined in:
- lib/couchrest.rb,
lib/couchrest/design.rb,
lib/couchrest/server.rb,
lib/couchrest/version.rb,
lib/couchrest/database.rb,
lib/couchrest/document.rb,
lib/couchrest/rest_api.rb,
lib/couchrest/attributes.rb,
lib/couchrest/connection.rb,
lib/couchrest/exceptions.rb,
lib/couchrest/helper/pager.rb,
lib/couchrest/commands/push.rb,
lib/couchrest/helper/upgrade.rb,
lib/couchrest/commands/generate.rb,
lib/couchrest/helper/attachments.rb,
lib/couchrest/middlewares/logger.rb,
lib/couchrest/helper/stream_row_parser.rb,
lib/couchrest/support/inheritable_attributes.rb
Overview
Copyright © 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
Defined Under Namespace
Modules: Attachments, Attributes, Commands, Exceptions, InheritableAttributes, RestAPI Classes: Connection, Database, Design, Document, Exception, Logger, Pager, RequestFailed, Server, ServerBrokeConnection, StreamRowParser, Upgrade
Constant Summary collapse
- VERSION =
File.read(File.('../../../VERSION', __FILE__)).strip
- STATUSES =
{ 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 304 => 'Not Modified', 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 409 => 'Conflict', 412 => 'Precondition Failed', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', }
- @@decode_json_objects =
false
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.
-
.decode_json_objects ⇒ Object
When set to true, CouchRest.get tries to decode the JSON returned from CouchDB into a Ruby object.
- .decode_json_objects=(value) ⇒ Object
-
.new(*opts) ⇒ Object
Instantiate a new Server object.
- .paramify_url(url, params = {}) ⇒ Object
- .params_to_query(params) ⇒ Object
- .parse(url) ⇒ Object
-
.proxy(url) ⇒ Object
Set default proxy to use in connections.
Methods included from RestAPI
copy, delete, get, head, post, put
Class Method Details
.database(url) ⇒ Object
107 108 109 110 111 |
# File 'lib/couchrest.rb', line 107 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
101 102 103 104 105 |
# File 'lib/couchrest.rb', line 101 def database! url parsed = parse url cr = CouchRest.new(parsed[:host]) cr.database!(parsed[:database]) end |
.decode_json_objects ⇒ Object
When set to true, CouchRest.get tries to decode the JSON returned from CouchDB into a Ruby object. Default: false.
138 139 140 |
# File 'lib/couchrest.rb', line 138 def decode_json_objects @@decode_json_objects end |
.decode_json_objects=(value) ⇒ Object
132 133 134 |
# File 'lib/couchrest.rb', line 132 def decode_json_objects=(value) @@decode_json_objects = value end |
.new(*opts) ⇒ Object
Instantiate a new Server object
55 56 57 |
# File 'lib/couchrest.rb', line 55 def new(*opts) Server.new(*opts) end |
.paramify_url(url, params = {}) ⇒ Object
113 114 115 116 |
# File 'lib/couchrest.rb', line 113 def paramify_url url, params = {} query = params_to_query(params) query ? "#{url}?#{query}" : url end |
.params_to_query(params) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/couchrest.rb', line 118 def params_to_query(params) if params && !params.empty? query = params.collect do |k,v| v = MultiJson.encode(v) if %w{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") query else nil end end |
.parse(url) ⇒ Object
59 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 |
# File 'lib/couchrest.rb', line 59 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 default proxy to use in connections
94 95 96 |
# File 'lib/couchrest.rb', line 94 def proxy url CouchRest::Connection.proxy = url end |