Class: Datacentred::Model::Role

Inherits:
Base
  • Object
show all
Defined in:
lib/datacentred/model/role.rb

Overview

A role on your DataCentred account.

Roles allow simple setup of user permissions via the creation of roles, then assigning those roles to users.

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Datacentred::Model::Base

Instance Attribute Details

#adminBoolean

Returns the current value of admin

Returns:

  • (Boolean)

    the current value of admin



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def admin
  @admin
end

#created_atTime (readonly)

Returns the current value of created_at

Returns:

  • (Time)

    the current value of created_at



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def created_at
  @created_at
end

#idString

Returns the current value of id

Returns:

  • (String)

    the current value of id



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def id
  @id
end

#nameString

Returns the current value of name

Returns:

  • (String)

    the current value of name



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def name
  @name
end

#permissions[String]

Returns the current value of permissions

Returns:

  • ([String])

    the current value of permissions



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def permissions
  @permissions
end

#updated_atTime (readonly)

Returns the current value of updated_at

Returns:

  • (Time)

    the current value of updated_at



13
14
15
# File 'lib/datacentred/model/role.rb', line 13

def updated_at
  @updated_at
end

Class Method Details

.add_user(role_id:, user_id:) ⇒ Boolean

Add new user to this role, giving them the associated permissions.

Parameters:

  • role_id (String)

    The unique identifier for this role.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (Boolean)

    Confirms that user was added (or is already present).

Raises:



83
84
85
86
# File 'lib/datacentred/model/role.rb', line 83

def add_user(role_id:, user_id:)
  Request::Roles.add_user role_id, user_id
  true
end

.all[Role]

List all available roles.

Returns:

  • ([Role])

    A collection of all roles on this account.

Raises:



29
30
31
# File 'lib/datacentred/model/role.rb', line 29

def all
  Request::Roles.list.map{|role| new role }
end

.create(params) ⇒ Role

Create a new role.

Parameters:

  • params (Hash)

    Role attributes.

Returns:

  • (Role)

    New role.

Raises:



21
22
23
# File 'lib/datacentred/model/role.rb', line 21

def create(params)
  new Request::Roles.create params
end

.destroy(id) ⇒ Boolean

Permanently remove the specified role.

Parameters:

  • id (String)

    The unique identifier for this role.

Returns:

  • (Boolean)

    Confirms the role was destroyed.

Raises:



62
63
64
65
# File 'lib/datacentred/model/role.rb', line 62

def destroy(id)
  Request::Roles.destroy id
  true
end

.find(id) ⇒ Role

Find a role by unique ID.

Parameters:

  • id (String)

    The unique identifier for this role.

Returns:

  • (Role)

    The role, if it exists.

Raises:



39
40
41
# File 'lib/datacentred/model/role.rb', line 39

def find(id)
  new Request::Roles.show id
end

.remove_user(role_id:, user_id:) ⇒ Boolean

Remove user from this role, revoking the associated permissions.

Parameters:

  • role_id (String)

    The unique identifier for this role.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (Boolean)

    Confirms that user was removed (or is already absent).

Raises:



95
96
97
98
# File 'lib/datacentred/model/role.rb', line 95

def remove_user(role_id:, user_id:)
  Request::Roles.remove_user role_id, user_id
  true
end

.update(id, params) ⇒ Role

Update a role by unique ID.

Parameters:

  • id (String)

    The unique identifier for this role.

  • params (Hash)

    Role attributes.

Returns:

  • (Role)

    The updated role.

Raises:



51
52
53
# File 'lib/datacentred/model/role.rb', line 51

def update(id, params)
  new Request::Roles.update id, params
end

.users(id) ⇒ [User]

List all users assigned to this role.

Parameters:

  • id (String)

    The unique identifier for this role.

Returns:

  • ([User])

    A collection of the role's users.

Raises:



72
73
74
# File 'lib/datacentred/model/role.rb', line 72

def users(id)
  Request::Roles.list_users(id).map{|user| new user }
end