Class: CFoundry::V1::User
- Inherits:
-
Object
- Object
- CFoundry::V1::User
- Defined in:
- lib/cfoundry/v1/user.rb
Overview
Class for representing a user on a given target (via Client).
Does not guarantee that the user exists; used for both user creation and retrieval, as the attributes are all lazily retrieved. Setting attributes does not perform any requests; use #update! to commit your changes.
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
User email.
Instance Method Summary collapse
-
#admin? ⇒ Boolean
Check if the user is an administrator.
-
#create! ⇒ Object
Create the user on the target.
-
#delete! ⇒ Object
Delete the user from the target.
-
#exists? ⇒ Boolean
Check if the user exists on the target.
-
#initialize(email, client, manifest = nil) ⇒ User
constructor
Create a User object.
-
#inspect ⇒ Object
Show string representing the user.
-
#password=(str) ⇒ Object
Set the user’s password.
-
#update!(what = {}) ⇒ Object
Update user attributes.
Constructor Details
#initialize(email, client, manifest = nil) ⇒ User
Create a User object.
You’ll usually call Client#user instead
15 16 17 18 19 |
# File 'lib/cfoundry/v1/user.rb', line 15 def initialize(email, client, manifest = nil) @email = email @client = client @manifest = manifest end |
Instance Attribute Details
#email ⇒ Object (readonly)
User email.
9 10 11 |
# File 'lib/cfoundry/v1/user.rb', line 9 def email @email end |
Instance Method Details
#admin? ⇒ Boolean
Check if the user is an administrator.
53 54 55 |
# File 'lib/cfoundry/v1/user.rb', line 53 def admin? manifest[:admin] end |
#create! ⇒ Object
Create the user on the target.
Call this after setting the various attributes.
34 35 36 |
# File 'lib/cfoundry/v1/user.rb', line 34 def create! @client.base.create_user(@manifest.merge(:email => @email)) end |
#delete! ⇒ Object
Delete the user from the target.
27 28 29 |
# File 'lib/cfoundry/v1/user.rb', line 27 def delete! @client.base.delete_user(@email) end |
#exists? ⇒ Boolean
Check if the user exists on the target.
45 46 47 48 49 50 |
# File 'lib/cfoundry/v1/user.rb', line 45 def exists? @client.base.user(@email) true rescue CFoundry::Denied false end |
#inspect ⇒ Object
Show string representing the user.
22 23 24 |
# File 'lib/cfoundry/v1/user.rb', line 22 def inspect "#<User '#@email'>" end |
#password=(str) ⇒ Object
Set the user’s password.
Call #update! after using this.
60 61 62 |
# File 'lib/cfoundry/v1/user.rb', line 60 def password=(str) manifest[:password] = str end |
#update!(what = {}) ⇒ Object
Update user attributes.
39 40 41 42 |
# File 'lib/cfoundry/v1/user.rb', line 39 def update!(what = {}) @client.base.update_user(@email, manifest.merge(what)) @manifest = nil end |