Module: CouchRest
- Defined in:
- lib/couchrest.rb,
lib/couchrest/core/server.rb,
lib/couchrest/helper/pager.rb,
lib/couchrest/commands/push.rb,
lib/couchrest/core/database.rb,
lib/couchrest/helper/streamer.rb,
lib/couchrest/commands/generate.rb,
lib/couchrest/helper/file_manager.rb
Defined Under Namespace
Modules: Commands
Classes: Database, FileManager, Pager, Server, Streamer
Class Method Summary
collapse
Class Method Details
.database(url) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/couchrest.rb', line 86
def database url
uri = URI.parse url
path = uri.path
uri.path = ''
cr = CouchRest.new(uri.to_s)
cr.database(path)
end
|
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created
78
79
80
81
82
83
84
|
# File 'lib/couchrest.rb', line 78
def database! url
uri = URI.parse url
path = uri.path
uri.path = ''
cr = CouchRest.new(uri.to_s)
cr.database!(path)
end
|
.delete(uri) ⇒ Object
108
109
110
|
# File 'lib/couchrest.rb', line 108
def delete uri
JSON.parse(RestClient.delete(uri))
end
|
.get(uri) ⇒ Object
99
100
101
|
# File 'lib/couchrest.rb', line 99
def get uri
JSON.parse(RestClient.get(uri), :max_nesting => false)
end
|
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
40
41
42
|
# File 'lib/couchrest.rb', line 40
def new(*opts)
Server.new(*opts)
end
|
.paramify_url(url, params = nil) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/couchrest.rb', line 112
def paramify_url url, params = nil
if params
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/couchrest.rb', line 44
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 || "localhost:5984",
:database => db,
:doc => docid
}
end
|
.post(uri, doc = nil) ⇒ Object
103
104
105
106
|
# File 'lib/couchrest.rb', line 103
def post uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.post(uri, payload))
end
|
.put(uri, doc = nil) ⇒ Object
94
95
96
97
|
# File 'lib/couchrest.rb', line 94
def put uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.put(uri, payload))
end
|