Class: Authorization::ControllerHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/role-authz/authorization/controller_helper.rb

Instance Method Summary collapse

Constructor Details

#initializeControllerHelper

Returns a new instance of ControllerHelper.



6
7
8
9
# File 'lib/role-authz/authorization/controller_helper.rb', line 6

def initialize
  @working_roles = []
  @permissions_list = {}
end

Instance Method Details

#actions_for(role) ⇒ Object



30
31
32
# File 'lib/role-authz/authorization/controller_helper.rb', line 30

def actions_for(role)
  @permissions_list[role] || []
end

#allow(*the_actions) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/role-authz/authorization/controller_helper.rb', line 18

def allow(*the_actions)
  raise NoCurrentForRoleStatement unless !@working_roles.empty?
  @working_roles.each do |current_role|
    if !@permissions_list.include?(current_role)
      @permissions_list[current_role] = []
    end
    @permissions_list[current_role] += the_actions
  end
  @working_roles.clear
  self
end

#for_roles(*the_roles) ⇒ Object Also known as: for_role



11
12
13
14
15
# File 'lib/role-authz/authorization/controller_helper.rb', line 11

def for_roles(*the_roles)
  raise OpenForRoleStatement unless @working_roles.empty?
  @working_roles += the_roles
  self
end