Class: CouchDB::Database

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/couchdb/database.rb', line 9

def name
  @name
end

#serverObject (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_optionsObject



59
60
61
# File 'lib/couchdb/database.rb', line 59

def authentication_options
  @server.authentication_options
end

#create!Object



23
24
25
# File 'lib/couchdb/database.rb', line 23

def create!
  Transport::JSON.request :put, url, authentication_options.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, authentication_options.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



51
52
53
# File 'lib/couchdb/database.rb', line 51

def documents(options = { })
  Collection.new self, url + "/_all_docs", options
end

#exists?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/couchdb/database.rb', line 43

def exists?
  @server.database_names.include? @name
end

#informationObject



39
40
41
# File 'lib/couchdb/database.rb', line 39

def information
  Transport::JSON.request :get, url, authentication_options.merge(:expected_status_code => 200)
end

#securityObject



55
56
57
# File 'lib/couchdb/database.rb', line 55

def security
  @security ||= CouchDB::Security.new self
end

#urlObject



47
48
49
# File 'lib/couchdb/database.rb', line 47

def url
  "#{@server.url}/#{@name}"
end