Class: Couchy::Server
- Inherits:
-
Object
- Object
- Couchy::Server
- Defined in:
- lib/couchy/server.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#create_db(name) ⇒ Couchy::Database
Creates a database.
-
#database(name) ⇒ Couchy::Database
Gets a new [Couchy::Database] for the database.
-
#databases ⇒ Array
Gets a list of all the databases available on the server.
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#info ⇒ Hash
Gets information about the server.
-
#initialize(uri) ⇒ Server
constructor
A new instance of Server.
- #post(path, doc = nil, params = {}) ⇒ Object
- #put(path, doc = nil) ⇒ Object
-
#restart! ⇒ Hash
Restarts the server.
Constructor Details
#initialize(uri) ⇒ Server
Returns a new instance of Server.
5 6 7 |
# File 'lib/couchy/server.rb', line 5 def initialize(uri) @uri = Addressable::URI.parse(uri) end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/couchy/server.rb', line 3 def uri @uri end |
Instance Method Details
#create_db(name) ⇒ Couchy::Database
Creates a database
44 45 46 47 |
# File 'lib/couchy/server.rb', line 44 def create_db(name) put(name) database(name) end |
#database(name) ⇒ Couchy::Database
Gets a new [Couchy::Database] for the database
35 36 37 |
# File 'lib/couchy/server.rb', line 35 def database(name) Database.new(self, name) end |
#databases ⇒ Array
Gets a list of all the databases available on the server
26 27 28 |
# File 'lib/couchy/server.rb', line 26 def databases get '_all_dbs' end |
#delete(path, params = {}) ⇒ Object
66 67 68 |
# File 'lib/couchy/server.rb', line 66 def delete(path, params={}) json RestClient.delete(uri_for(path, params)) end |
#get(path, params = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/couchy/server.rb', line 49 def get(path, params={}) need_json = !params.delete(:no_json) response = RestClient.get(uri_for(path, params)) need_json ? json(response, :max_nesting => false) : response end |
#info ⇒ Hash
Gets information about the server
12 13 14 |
# File 'lib/couchy/server.rb', line 12 def info get '/' end |
#post(path, doc = nil, params = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/couchy/server.rb', line 55 def post(path, doc=nil, params={}) headers = params.delete(:headers) payload = doc.to_json if doc json RestClient.post(uri_for(path, params), payload, headers) end |
#put(path, doc = nil) ⇒ Object
61 62 63 64 |
# File 'lib/couchy/server.rb', line 61 def put(path, doc=nil) payload = doc.to_json if doc json RestClient.put(uri_for(path), payload) end |
#restart! ⇒ Hash
Restarts the server
19 20 21 |
# File 'lib/couchy/server.rb', line 19 def restart! post '_restart' end |