Class: Datacentred::Model::Role
- 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
-
#admin ⇒ Boolean
The current value of admin.
-
#created_at ⇒ Time
readonly
The current value of created_at.
-
#id ⇒ String
The current value of id.
-
#name ⇒ String
The current value of name.
-
#permissions ⇒ [String]
The current value of permissions.
-
#updated_at ⇒ Time
readonly
The current value of updated_at.
Class Method Summary collapse
-
.add_user(role_id:, user_id:) ⇒ Boolean
Add new user to this role, giving them the associated permissions.
-
.all ⇒ [Role]
List all available roles.
-
.create(params) ⇒ Role
Create a new role.
-
.destroy(id) ⇒ Boolean
Permanently remove the specified role.
-
.find(id) ⇒ Role
Find a role by unique ID.
-
.remove_user(role_id:, user_id:) ⇒ Boolean
Remove user from this role, revoking the associated permissions.
-
.update(id, params) ⇒ Role
Update a role by unique ID.
-
.users(id) ⇒ [User]
List all users assigned to this role.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Datacentred::Model::Base
Instance Attribute Details
#admin ⇒ Boolean
Returns the current value of admin
13 14 15 |
# File 'lib/datacentred/model/role.rb', line 13 def admin @admin end |
#created_at ⇒ Time (readonly)
Returns the current value of created_at
13 14 15 |
# File 'lib/datacentred/model/role.rb', line 13 def created_at @created_at end |
#id ⇒ String
Returns the current value of id
13 14 15 |
# File 'lib/datacentred/model/role.rb', line 13 def id @id end |
#name ⇒ String
Returns 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
13 14 15 |
# File 'lib/datacentred/model/role.rb', line 13 def @permissions end |
#updated_at ⇒ Time (readonly)
Returns 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.
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.
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.
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.
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.
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.
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.
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.
72 73 74 |
# File 'lib/datacentred/model/role.rb', line 72 def users(id) Request::Roles.list_users(id).map{|user| new user } end |