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.
- #change_password!(new, old) ⇒ Object
-
#create! ⇒ Object
Create the user on the target.
-
#delete! ⇒ Object
Delete the user from the target.
-
#eql?(other) ⇒ Boolean
(also: #==)
Basic equality test by email.
-
#exists? ⇒ Boolean
Check if the user exists on the target.
- #guid ⇒ Object
-
#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.
59 60 61 |
# File 'lib/cfoundry/v1/user.rb', line 59 def admin? manifest[:admin] end |
#change_password!(new, old) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/cfoundry/v1/user.rb', line 74 def change_password!(new, old) if @client.base.uaa @client.base.uaa.change_password(guid, new, old) else self.password = new update! end end |
#create! ⇒ Object
Create the user on the target.
Call this after setting the various attributes.
40 41 42 |
# File 'lib/cfoundry/v1/user.rb', line 40 def create! @client.base.create_user(@manifest.merge(:email => @email)) end |
#delete! ⇒ Object
Delete the user from the target.
33 34 35 |
# File 'lib/cfoundry/v1/user.rb', line 33 def delete! @client.base.delete_user(@email) end |
#eql?(other) ⇒ Boolean Also known as: ==
Basic equality test by email.
27 28 29 |
# File 'lib/cfoundry/v1/user.rb', line 27 def eql?(other) other.is_a?(self.class) && other.email == @email end |
#exists? ⇒ Boolean
Check if the user exists on the target.
51 52 53 54 55 56 |
# File 'lib/cfoundry/v1/user.rb', line 51 def exists? @client.base.user(@email) true rescue CFoundry::Denied false end |
#guid ⇒ Object
70 71 72 |
# File 'lib/cfoundry/v1/user.rb', line 70 def guid @guid ||= @client.base.token_data[:user_id] 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.
66 67 68 |
# File 'lib/cfoundry/v1/user.rb', line 66 def password=(str) manifest[:password] = str end |
#update!(what = {}) ⇒ Object
Update user attributes.
45 46 47 48 |
# File 'lib/cfoundry/v1/user.rb', line 45 def update!(what = {}) @client.base.update_user(@email, manifest.merge(what)) @manifest = nil end |