Class: CouchDB::User

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

Overview

Abstracts a CouchDB user.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_database, name) ⇒ User

Returns a new instance of User.



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

def initialize(user_database, name)
  @user_database = user_database

  @document = CouchDB::Document.new @user_database.database
  @document["_id"] = "org.couchdb.user:#{name}"
  @document["type"] = "user"
  @document["name"] = name
  @document["salt"] = @user_database.server.password_salt
  @document["roles"] = [ ]
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



8
9
10
# File 'lib/couchdb/user.rb', line 8

def document
  @document
end

#user_databaseObject (readonly)

Returns the value of attribute user_database.



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

def user_database
  @user_database
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
# File 'lib/couchdb/user.rb', line 45

def ==(other)
  @document == other.document
end

#destroyObject



58
59
60
# File 'lib/couchdb/user.rb', line 58

def destroy
  @document.destroy
end

#idObject



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

def id
  @document["_id"]
end

#loadObject



49
50
51
# File 'lib/couchdb/user.rb', line 49

def load
  @document.load
end

#nameObject



25
26
27
# File 'lib/couchdb/user.rb', line 25

def name
  @document["name"]
end

#passwordObject



33
34
35
# File 'lib/couchdb/user.rb', line 33

def password
  @document["password_sha"]
end

#password=(value) ⇒ Object



29
30
31
# File 'lib/couchdb/user.rb', line 29

def password=(value)
  @document["password_sha"] = Digest::SHA1.hexdigest(value + @user_database.database.server.password_salt)
end

#rolesObject



41
42
43
# File 'lib/couchdb/user.rb', line 41

def roles
  @document["roles"]
end

#roles=(value) ⇒ Object



37
38
39
# File 'lib/couchdb/user.rb', line 37

def roles=(value)
  @document["roles"] = value || [ ]
end

#saveObject



53
54
55
56
# File 'lib/couchdb/user.rb', line 53

def save
  @document.fetch_rev
  @document.save
end