Module: YamledAcl

Defined in:
lib/yamled_acl.rb,
lib/yamled_acl/version.rb,
lib/yamled_acl/exceptions.rb,
lib/yamled_acl/controller_extension.rb

Defined Under Namespace

Modules: ControllerExtension Classes: AccessDenied, Error, NotExistingGroup, UninitializedGroup, UninitializedResource

Constant Summary collapse

ALLOW_ALL =
'allow_all'
DENY_ALL =
'deny_all'
VERSION =
"0.3.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.files_with_permissions_pathObject

Returns the value of attribute files_with_permissions_path.



12
13
14
# File 'lib/yamled_acl.rb', line 12

def files_with_permissions_path
  @files_with_permissions_path
end

.groupsObject

Returns the value of attribute groups.



14
15
16
# File 'lib/yamled_acl.rb', line 14

def groups
  @groups
end

.guest_group_nameObject

Returns the value of attribute guest_group_name.



15
16
17
# File 'lib/yamled_acl.rb', line 15

def guest_group_name
  @guest_group_name
end

.reload_permissions_on_each_requestObject

Returns the value of attribute reload_permissions_on_each_request.



13
14
15
# File 'lib/yamled_acl.rb', line 13

def reload_permissions_on_each_request
  @reload_permissions_on_each_request
end

Class Method Details

.init(group_name, resource_name) ⇒ Object

Initializes ACL by giving logged user group name and currently processed resource name.



40
41
42
43
44
# File 'lib/yamled_acl.rb', line 40

def self.init(group_name, resource_name)
  init_resource(resource_name)
  init_group(group_name)
  load_action_permissions_for(Thread.current[:yamled_acl_resource_name])
end

.permission?(action, resource = nil) ⇒ Boolean

Method used for checking permissions. Optional resource name may be specified to check permission for other resource than curently processed.

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/yamled_acl.rb', line 48

def self.permission?(action, resource = nil)
  Thread.current.key?(:yamled_acl_group) or raise(UninitializedGroup)
  if resource.nil?
    check(@actions_permissions[Thread.current[:yamled_acl_resource_name]][action.to_s])
  else
    load_action_permissions_for(resource)
    check(@actions_permissions[resource.to_s][action.to_s])
  end
end

.setup {|_self| ... } ⇒ Object

Provides configuration options:

YamledAcl.setup do |config|
  config.files_with_permissions_path = 'other/than/default/path'
  config.reload_permissions_on_each_request = Rails.env.development?
  config.groups = %w(admin member)
  config.guest_group_name = 'visitor'
end

Yields:

  • (_self)

Yield Parameters:

  • _self (YamledAcl)

    the object that the method was called on



33
34
35
36
# File 'lib/yamled_acl.rb', line 33

def self.setup
  yield(self)
  @groups << @guest_group_name
end