Sha256: d24f465cb7dc9dae4f2620cd99ac1eac54f0113010965945ce77818eea7d4750

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 KB

Contents

module CFoundry::V1
  # 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.
  class User
    # User email.
    attr_reader :email


    # Create a User object.
    #
    # You'll usually call Client#user instead
    def initialize(email, client, manifest = nil)
      @email = email
      @client = client
      @manifest = manifest
    end

    # Show string representing the user.
    def inspect
      "#<User '#@email'>"
    end

    # Delete the user from the target.
    def delete!
      @client.base.delete_user(@email)
    end

    # Create the user on the target.
    #
    # Call this after setting the various attributes.
    def create!
      @client.base.create_user(@manifest.merge(:email => @email))
    end

    # Update user attributes.
    def update!(what = {})
      @client.base.update_user(@email, manifest.merge(what))
      @manifest = nil
    end

    # Check if the user exists on the target.
    def exists?
      @client.base.user(@email)
      true
    rescue CFoundry::Denied
      false
    end

    # Check if the user is an administrator.
    def admin?
      manifest[:admin]
    end

    # Set the user's password.
    #
    # Call #update! after using this.
    def password=(str)
      manifest[:password] = str
    end

    private

    def manifest
      @manifest ||= @client.base.user(@email)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
cfoundry-0.3.20 lib/cfoundry/v1/user.rb
cfoundry-0.3.19 lib/cfoundry/v1/user.rb
cfoundry-0.3.18 lib/cfoundry/v1/user.rb
cfoundry-0.3.17 lib/cfoundry/v1/user.rb
cfoundry-0.3.16 lib/cfoundry/v1/user.rb
cfoundry-0.3.15 lib/cfoundry/v1/user.rb
cfoundry-0.3.14 lib/cfoundry/v1/user.rb
cfoundry-0.3.13 lib/cfoundry/v1/user.rb
cfoundry-0.3.12 lib/cfoundry/v1/user.rb
cfoundry-0.3.11 lib/cfoundry/v1/user.rb
cfoundry-0.3.10 lib/cfoundry/v1/user.rb
cfoundry-0.3.9 lib/cfoundry/v1/user.rb
cfoundry-0.3.8 lib/cfoundry/v1/user.rb
cfoundry-0.3.7 lib/cfoundry/v1/user.rb
cfoundry-0.3.6 lib/cfoundry/v1/user.rb
cfoundry-0.3.5 lib/cfoundry/v1/user.rb
cfoundry-0.3.4 lib/cfoundry/v1/user.rb
cfoundry-0.3.3 lib/cfoundry/v1/user.rb
cfoundry-0.3.2 lib/cfoundry/v1/user.rb
cfoundry-0.3.1 lib/cfoundry/v1/user.rb