Class: CouchDB::Security

Inherits:
Object
  • Object
show all
Defined in:
lib/couchdb/security.rb

Overview

Abstracts a CouchDB database security document.

Defined Under Namespace

Classes: UsersAndRolesProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ Security

Returns a new instance of Security.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/couchdb/security.rb', line 8

def initialize(database)
  @database = database

  @document = CouchDB::Document.new @database
  @document.id = "_security"
  @document.fetch_rev
  @document["admins"] = { }
  @document["readers"] = { }

  @administrators = UsersAndRolesProxy.new @document["admins"]
  @readers = UsersAndRolesProxy.new @document["readers"]
end

Instance Attribute Details

#administratorsObject (readonly)

Returns the value of attribute administrators.



5
6
7
# File 'lib/couchdb/security.rb', line 5

def administrators
  @administrators
end

#readersObject (readonly)

Returns the value of attribute readers.



6
7
8
# File 'lib/couchdb/security.rb', line 6

def readers
  @readers
end

Instance Method Details

#loadObject



21
22
23
# File 'lib/couchdb/security.rb', line 21

def load
  @document.load
end

#saveObject



25
26
27
28
29
# File 'lib/couchdb/security.rb', line 25

def save
  @document.save
rescue Transport::UnexpectedStatusCodeError => error
  raise error unless error.status_code == 200
end