Module: CouchRest
- Defined in:
- lib/couchrest.rb,
lib/couchrest/core/view.rb,
lib/couchrest/core/model.rb,
lib/couchrest/core/design.rb,
lib/couchrest/core/server.rb,
lib/couchrest/helper/pager.rb,
lib/couchrest/commands/push.rb,
lib/couchrest/core/database.rb,
lib/couchrest/core/document.rb,
lib/couchrest/helper/streamer.rb,
lib/couchrest/commands/generate.rb
Overview
CouchRest::Model - Document modeling, the CouchDB way
Defined Under Namespace
Modules: Commands
Classes: Database, Design, Document, Model, Pager, Response, Server, Streamer, View
Constant Summary
collapse
- VERSION =
'0.12.6'
Class Method Summary
collapse
Class Method Details
.copy(uri, destination) ⇒ Object
124
125
126
|
# File 'lib/couchrest.rb', line 124
def copy uri, destination
JSON.parse(RestClient.copy(uri, {'Destination' => destination}))
end
|
.database(url) ⇒ Object
100
101
102
103
104
|
# File 'lib/couchrest.rb', line 100
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
94
95
96
97
98
|
# File 'lib/couchrest.rb', line 94
def database! url
parsed = parse url
cr = CouchRest.new(parsed[:host])
cr.database!(parsed[:database])
end
|
.delete(uri) ⇒ Object
120
121
122
|
# File 'lib/couchrest.rb', line 120
def delete uri
JSON.parse(RestClient.delete(uri))
end
|
.get(uri) ⇒ Object
111
112
113
|
# File 'lib/couchrest.rb', line 111
def get uri
JSON.parse(RestClient.get(uri), :max_nesting => false)
end
|
.move(uri, destination) ⇒ Object
128
129
130
|
# File 'lib/couchrest.rb', line 128
def move uri, destination
JSON.parse(RestClient.move(uri, {'Destination' => destination}))
end
|
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
51
52
53
|
# File 'lib/couchrest.rb', line 51
def new(*opts)
Server.new(*opts)
end
|
.paramify_url(url, params = {}) ⇒ Object
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/couchrest.rb', line 132
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
55
56
57
58
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
|
# File 'lib/couchrest.rb', line 55
def parse url
case url
when /^http:\/\/(.*)\/(.*)\/(.*)/
host = $1
db = $2
docid = $3
when /^http:\/\/(.*)\/(.*)/
host = $1
db = $2
when /^http:\/\/(.*)/
host = $1
when /(.*)\/(.*)\/(.*)/
host = $1
db = $2
docid = $3
when /(.*)\/(.*)/
host = $1
db = $2
else
db = url
end
db = nil if db && db.empty?
{
:host => host || "127.0.0.1:5984",
:database => db,
:doc => docid
}
end
|
.post(uri, doc = nil) ⇒ Object
115
116
117
118
|
# File 'lib/couchrest.rb', line 115
def post uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.post(uri, payload))
end
|
.proxy(url) ⇒ Object
set proxy for RestClient to use
87
88
89
|
# File 'lib/couchrest.rb', line 87
def proxy url
RestClient.proxy = url
end
|
.put(uri, doc = nil) ⇒ Object
106
107
108
109
|
# File 'lib/couchrest.rb', line 106
def put uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.put(uri, payload))
end
|