Class: YaAcl::Builder

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

Defined Under Namespace

Classes: PrivilegeAssertProxy, PrivilegeProxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



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

def initialize
  self.acl = Acl.new
end

Instance Attribute Details

#aclObject

Returns the value of attribute acl.



3
4
5
# File 'lib/ya_acl/builder.rb', line 3

def acl
  @acl
end

Class Method Details

.build(&block) ⇒ Object



5
6
7
8
9
10
# File 'lib/ya_acl/builder.rb', line 5

def self.build &block
  builder = new
  builder.instance_eval &block
  builder.acl.freeze
  Acl.instance = builder.acl
end

Instance Method Details

#assert(name, param_names, &block) ⇒ Object



28
29
30
# File 'lib/ya_acl/builder.rb', line 28

def assert(name, param_names, &block)
  acl.add_assert Assert.new(name, param_names, &block)
end

#asserts(&block) ⇒ Object



24
25
26
# File 'lib/ya_acl/builder.rb', line 24

def asserts(&block)
  instance_eval &block
end

#resource(name, allow_roles = [], &block) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
# File 'lib/ya_acl/builder.rb', line 37

def resource(name, allow_roles = [], &block)
  raise ArgumentError, 'Options "allow_roles" must be Array' unless allow_roles.is_a? Array
  resource_allow_roles = allow_roles << @global_allow_role
  resource = Resource.new(name)
  acl.add_resource resource
  PrivilegeProxy.new(resource.name, resource_allow_roles, acl, block)
end

#resources(allow, &block) ⇒ Object



32
33
34
35
# File 'lib/ya_acl/builder.rb', line 32

def resources(allow, &block)
  @global_allow_role = allow
  instance_eval &block
end

#role(name, options = {}) ⇒ Object



20
21
22
# File 'lib/ya_acl/builder.rb', line 20

def role(name, options = {})
  acl.add_role Role.new(name, options)
end

#roles(&block) ⇒ Object



16
17
18
# File 'lib/ya_acl/builder.rb', line 16

def roles(&block)
  instance_eval &block
end