1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/identity/user.rb
Paul Thornthwaite 40c0cd7122 Make use of #persisted? method
In many places we were checking for identity which was the shorthand for
checking if the resource had been saved by the service.

The #persisted? method was added to show a clearer intent and also offer
minimal ActiveModel interface
2012-12-23 02:45:05 +00:00

53 lines
1.3 KiB
Ruby

require 'fog/core/model'
module Fog
module Rackspace
class Identity
class User < Fog::Model
identity :id
attribute :username
attribute :password, :alias => 'OS-KSADM:password'
attribute :email
attribute :enabled
attribute :created
attribute :updated
def save
requires :username, :email, :enabled
unless persisted?
data = connection.create_user(username, email, enabled, :password => password)
else
data = connection.update_user(identity, username, email, enabled, :password => password)
end
merge_attributes(data.body['user'])
true
end
def destroy
requires :identity
connection.delete_user(identity)
true
end
def roles
@roles ||= begin
Fog::Rackspace::Identity::Roles.new({
:connection => connection,
:user => self
})
end
end
def credentials
@credentials ||= begin
Fog::Rackspace::Identity::Credentials.new({
:connection => connection,
:user => self
})
end
end
end
end
end
end