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.



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

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



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

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

  asserts = {}
  if block_given?
    proxy = PrivilegeAssertProxy.new(asserts_block, all_allow_roles)
    asserts = proxy.asserts
  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