Class: CFoundry::User

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

Overview

Class for representing a user on a given target (via Client).

Goes 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

Instance Method Summary collapse

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/user.rb', line 15

def initialize(email, client, manifest = nil)
  @email = email
  @client = client
  @manifest = manifest
end

Instance Attribute Details

#emailObject (readonly)

User email.



9
10
11
# File 'lib/cfoundry/user.rb', line 9

def email
  @email
end

Instance Method Details

#admin?Boolean

Check if the user is an administrator.

Returns:

  • (Boolean)


52
53
54
# File 'lib/cfoundry/user.rb', line 52

def admin?
  manifest["admin"]
end

#create!Object

Create the user on the target.

Call this after setting the various attributes.



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

def create!
  @client.rest.create_user(@manifest.merge("email" => @email))
end

#delete!Object

Delete the user from the target.



26
27
28
# File 'lib/cfoundry/user.rb', line 26

def delete!
  @client.rest.delete_user(@email)
end

#exists?Boolean

Check if the user exists on the target.

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/cfoundry/user.rb', line 44

def exists?
  @client.rest.user(@email)
  true
rescue CFoundry::Denied
  false
end

#inspectObject

:nodoc:



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

def inspect # :nodoc:
  "#<User '#@email'>"
end

#password=(str) ⇒ Object

Set the user’s password.

Call #update! after using this.



59
60
61
# File 'lib/cfoundry/user.rb', line 59

def password=(str)
  manifest["password"] = str
end

#update!(what = {}) ⇒ Object

Update user attributes.



38
39
40
41
# File 'lib/cfoundry/user.rb', line 38

def update!(what = {})
  @client.rest.update_user(@email, manifest.merge(what))
  @manifest = nil
end