Class: YaAcl::Builder::PrivilegeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/ya_acl/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, allow_roles, acl, block) ⇒ PrivilegeProxy

Returns a new instance of PrivilegeProxy.



45
46
47
48
49
50
# File 'lib/ya_acl/builder.rb', line 45

def initialize(name, allow_roles, acl, block)
  @resource_name = name
  @allow_roles = allow_roles
  @acl = acl
  instance_eval &block
end

Instance Method Details

#privilege(privilege_name, roles = [], &asserts_block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ya_acl/builder.rb', line 52

def privilege(privilege_name, roles = [], &asserts_block)
  all_allow_roles = roles | @allow_roles

  asserts = {}
  if block_given?
    asserts = PrivilegeAssertProxy.build asserts_block, all_allow_roles
  end

  all_allow_roles.each do |role|
    if asserts[role]
      asserts[role].each do |assert|
        @acl.allow(@resource_name, privilege_name, role, assert)
      end
    else
      @acl.allow(@resource_name, privilege_name, role, nil)
    end
  end
end