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.



3
4
5
6
# File 'lib/role-authz/authorization/controller_helper.rb', line 3

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

Instance Method Details

#actions_for(role) ⇒ Object



25
26
27
# File 'lib/role-authz/authorization/controller_helper.rb', line 25

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

#allow(*the_actions) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/role-authz/authorization/controller_helper.rb', line 15

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

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



8
9
10
11
12
# File 'lib/role-authz/authorization/controller_helper.rb', line 8

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