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

- (Object) create(options = {})

Create a new Role

Examples:

create label: 'Admin'

Parameters:

  • options (defaults to: {})

    Params for creating the roles:

Options Hash (options):

  • :label (Object)

    Label for the role

  • :permission_ids (Object)

    An array of permission ids granted to the role.



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

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

- (Object) delete(id)

Delete a Role.

Parameters:

  • 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

- (Object) edit(id, options = {})

Edit a Role.

Examples:

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

Parameters:

  • id

    ID of the role

  • options (defaults to: {})

    Params for editing the roles, see `#create`

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

- (Object) list

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

- (Object) permissions

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

- (Object) show(id)

Show info for the given role.

Parameters:

  • 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