Class: CouchCrumbs::Server
- Inherits:
-
Object
- Object
- CouchCrumbs::Server
- Defined in:
- lib/couch_crumbs/server.rb
Overview
Represents an instance of a live running CouchDB server
Constant Summary collapse
- DEFAULT_URI =
"http://couchdb.local:5984".freeze
Instance Attribute Summary collapse
-
#status ⇒ Object
Returns the value of attribute status.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#databases ⇒ Object
Return an array of databases.
-
#initialize(opts = {}) ⇒ Server
constructor
Create a new instance of Server.
-
#uuids(count = 1) ⇒ Object
Return a new random UUID for use in documents.
Constructor Details
#initialize(opts = {}) ⇒ Server
Create a new instance of Server
13 14 15 16 17 |
# File 'lib/couch_crumbs/server.rb', line 13 def initialize(opts = {}) self.uri = opts[:uri] || DEFAULT_URI self.status = JSON.parse(RestClient.get(self.uri)) end |
Instance Attribute Details
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/couch_crumbs/server.rb', line 9 def status @status end |
#uri ⇒ Object
Returns the value of attribute uri.
9 10 11 |
# File 'lib/couch_crumbs/server.rb', line 9 def uri @uri end |
Instance Method Details
#databases ⇒ Object
TODO:
-
add a :refresh argument with a 10 second cache of the DBs
Return an array of databases
22 23 24 25 26 |
# File 'lib/couch_crumbs/server.rb', line 22 def databases JSON.parse(RestClient.get(File.join(self.uri, "_all_dbs"))).collect do |database_name| Database.new(:name => database_name) end end |
#uuids(count = 1) ⇒ Object
Return a new random UUID for use in documents
30 31 32 33 34 35 36 37 38 |
# File 'lib/couch_crumbs/server.rb', line 30 def uuids(count = 1) uuids = JSON.parse(RestClient.get(File.join(self.uri, "_uuids?count=#{ count }")))["uuids"] if count > 1 uuids else uuids.first end end |