Class: CouchDB::Database
- Inherits:
-
Object
- Object
- CouchDB::Database
- Defined in:
- lib/couchdb/database.rb
Overview
The Database class provides methods create, delete and retrieve informations of a CouchDB database.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #authentication_options ⇒ Object
- #compact! ⇒ Object
- #create! ⇒ Object
- #create_if_missing! ⇒ Object
- #delete! ⇒ Object
- #delete_if_exists! ⇒ Object
- #documents(options = { }) ⇒ Object
- #exists? ⇒ Boolean
- #information ⇒ Object
-
#initialize(server, name) ⇒ Database
constructor
A new instance of Database.
- #security ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(server, name) ⇒ Database
Returns a new instance of Database.
11 12 13 |
# File 'lib/couchdb/database.rb', line 11 def initialize(server, name) @server, @name = server, name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/couchdb/database.rb', line 9 def name @name end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/couchdb/database.rb', line 8 def server @server end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 |
# File 'lib/couchdb/database.rb', line 15 def ==(other) other.is_a?(self.class) && @name == other.name && @server == other.server end |
#===(other) ⇒ Object
19 20 21 |
# File 'lib/couchdb/database.rb', line 19 def ===(other) object_id == other.object_id end |
#authentication_options ⇒ Object
63 64 65 |
# File 'lib/couchdb/database.rb', line 63 def @server. end |
#compact! ⇒ Object
39 40 41 |
# File 'lib/couchdb/database.rb', line 39 def compact! Transport::JSON.request :post, "#{url}/_compact", .merge(:expected_status_code => 202, :body => { }) end |
#create! ⇒ Object
23 24 25 |
# File 'lib/couchdb/database.rb', line 23 def create! Transport::JSON.request :put, url, .merge(:expected_status_code => 201) end |
#create_if_missing! ⇒ Object
27 28 29 |
# File 'lib/couchdb/database.rb', line 27 def create_if_missing! create! unless exists? end |
#delete! ⇒ Object
31 32 33 |
# File 'lib/couchdb/database.rb', line 31 def delete! Transport::JSON.request :delete, url, .merge(:expected_status_code => 200) end |
#delete_if_exists! ⇒ Object
35 36 37 |
# File 'lib/couchdb/database.rb', line 35 def delete_if_exists! delete! if exists? end |
#documents(options = { }) ⇒ Object
55 56 57 |
# File 'lib/couchdb/database.rb', line 55 def documents( = { }) Collection.new self, url + "/_all_docs", end |
#exists? ⇒ Boolean
47 48 49 |
# File 'lib/couchdb/database.rb', line 47 def exists? @server.database_names.include? @name end |
#information ⇒ Object
43 44 45 |
# File 'lib/couchdb/database.rb', line 43 def information Transport::JSON.request :get, url, .merge(:expected_status_code => 200) end |
#security ⇒ Object
59 60 61 |
# File 'lib/couchdb/database.rb', line 59 def security @security ||= CouchDB::Security.new self end |
#url ⇒ Object
51 52 53 |
# File 'lib/couchdb/database.rb', line 51 def url "#{@server.url}/#{@name}" end |