Class: CouchDB::User
- Inherits:
-
Object
- Object
- CouchDB::User
- Defined in:
- lib/couchdb/user.rb
Overview
Abstracts a CouchDB user.
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#user_database ⇒ Object
readonly
Returns the value of attribute user_database.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
-
#initialize(user_database, name) ⇒ User
constructor
A new instance of User.
- #load ⇒ Object
- #name ⇒ Object
- #password ⇒ Object
- #password=(value) ⇒ Object
- #roles ⇒ Object
- #roles=(value) ⇒ Object
- #save ⇒ Object
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
#document ⇒ Object
Returns the value of attribute document.
8 9 10 |
# File 'lib/couchdb/user.rb', line 8 def document @document end |
#user_database ⇒ Object (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 |
#destroy ⇒ Object
58 59 60 |
# File 'lib/couchdb/user.rb', line 58 def destroy @document.destroy end |
#id ⇒ Object
21 22 23 |
# File 'lib/couchdb/user.rb', line 21 def id @document["_id"] end |
#load ⇒ Object
49 50 51 |
# File 'lib/couchdb/user.rb', line 49 def load @document.load end |
#name ⇒ Object
25 26 27 |
# File 'lib/couchdb/user.rb', line 25 def name @document["name"] end |
#password ⇒ Object
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 |
#roles ⇒ Object
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 |
#save ⇒ Object
53 54 55 56 |
# File 'lib/couchdb/user.rb', line 53 def save @document.fetch_rev @document.save end |