Class: CouchRest
- Inherits:
-
Object
- Object
- CouchRest
- Defined in:
- lib/pager.rb,
lib/database.rb,
lib/couchrest.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .delete(uri) ⇒ Object
- .get(uri) ⇒ Object
- .paramify_url(url, params = nil) ⇒ Object
- .post(uri, doc = nil) ⇒ Object
- .put(uri, doc = nil) ⇒ Object
Instance Method Summary collapse
-
#create_db(name) ⇒ Object
create a database.
- #database(name) ⇒ Object
-
#databases ⇒ Object
list all databases on the server.
-
#info ⇒ Object
get the welcome message.
-
#initialize(server = 'http://localhost:5984') ⇒ CouchRest
constructor
A new instance of CouchRest.
-
#restart! ⇒ Object
restart the couchdb instance.
Constructor Details
#initialize(server = 'http://localhost:5984') ⇒ CouchRest
Returns a new instance of CouchRest.
10 11 12 |
# File 'lib/couchrest.rb', line 10 def initialize server = 'http://localhost:5984' @uri = server end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
9 10 11 |
# File 'lib/couchrest.rb', line 9 def uri @uri end |
Class Method Details
.delete(uri) ⇒ Object
54 55 56 |
# File 'lib/couchrest.rb', line 54 def delete uri JSON.parse(RestClient.delete(uri)) end |
.get(uri) ⇒ Object
45 46 47 |
# File 'lib/couchrest.rb', line 45 def get uri JSON.parse(RestClient.get(uri), :max_nesting => false) end |
.paramify_url(url, params = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/couchrest.rb', line 58 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 |
.post(uri, doc = nil) ⇒ Object
49 50 51 52 |
# File 'lib/couchrest.rb', line 49 def post uri, doc = nil payload = doc.to_json if doc JSON.parse(RestClient.post(uri, payload)) end |
.put(uri, doc = nil) ⇒ Object
40 41 42 43 |
# File 'lib/couchrest.rb', line 40 def put uri, doc = nil payload = doc.to_json if doc JSON.parse(RestClient.put(uri, payload)) end |
Instance Method Details
#create_db(name) ⇒ Object
create a database
34 35 36 37 |
# File 'lib/couchrest.rb', line 34 def create_db name CouchRest.put "#{@uri}/#{name}" database name end |
#database(name) ⇒ Object
19 20 21 |
# File 'lib/couchrest.rb', line 19 def database name CouchRest::Database.new(@uri, name) end |
#databases ⇒ Object
list all databases on the server
15 16 17 |
# File 'lib/couchrest.rb', line 15 def databases CouchRest.get "#{@uri}/_all_dbs" end |