Class: Squall::Role

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

Overview

OnApp Role

Instance Attribute Summary

Attributes inherited from Base

#result, #success

Instance Method Summary collapse

Methods inherited from Base

#check_config, #default_params, #key_for_class, #request

Instance Method Details

#create(options = {}) ⇒ Object

Public: Create a new Role

options - Params for creating the roles:

:label          - Label for the role
:permission_ids - An array of permission ids granted to the role.

Example

create label: 'Admin'


31
32
33
# File 'lib/squall/role.rb', line 31

def create(options = {})
  request(:post, '/roles.json', default_params(options))
end

#delete(id) ⇒ Object

Public: Delete a Role.

id - ID of the role

Returns a Hash.



54
55
56
# File 'lib/squall/role.rb', line 54

def delete(id)
  request(:delete, "/roles/#{id}.json")
end

#edit(id, options = {}) ⇒ Object

Public: Edit a Role.

id - ID of the role options - Params for editing the roles, see ‘#create`

Example

edit 1, label: 'myrole', permission_ids: [1, 3]

Returns a Hash.



45
46
47
# File 'lib/squall/role.rb', line 45

def edit(id, options = {})
  request(:put, "/roles/#{id}.json", default_params(options))
end

#listObject

Public: Lists all roles.

Returns an Array.



7
8
9
10
# File 'lib/squall/role.rb', line 7

def list
  response = request(:get, '/roles.json')
  response.collect { |role| role['role']}
end

#permissionsObject

Public: Lists all permissions available.

Returns an Array.



61
62
63
64
# File 'lib/squall/role.rb', line 61

def permissions
  response = request(:get, '/permissions.json')
  response.collect { |perm| perm['permission'] }
end

#show(id) ⇒ Object

Public: Show info for the given role.

id - ID of the role

Returns a Hash.



17
18
19
20
# File 'lib/squall/role.rb', line 17

def show(id)
  response = request(:get, "/roles/#{id}.json")
  response["role"]
end