Class: Aclatraz::ACL::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/aclatraz/acl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, &block) ⇒ Action

Returns a new instance of Action.



7
8
9
10
11
# File 'lib/aclatraz/acl.rb', line 7

def initialize(parent, &block) 
  @parent = parent
  @permissions = Dictionary.new {|h,k| h[k] = false}.merge(parent.permissions)
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#permissionsObject (readonly)

All permissions defined in this action.



5
6
7
# File 'lib/aclatraz/acl.rb', line 5

def permissions
  @permissions
end

Instance Method Details

#allObject

Syntactic sugar for aliasing all permissions.

Examples

allow all
deny all


47
48
49
# File 'lib/aclatraz/acl.rb', line 47

def all
  true
end

#allow(permission) ⇒ Object

Add permission for objects which have given role.

Examples

allow :admin
allow :owner_of => "object"
allow :owner_of => :object
allow :owner_of => object
allow :manager_of => ClassName
allow all


23
24
25
# File 'lib/aclatraz/acl.rb', line 23

def allow(permission)
  @permissions[permission] = true
end

#clone(parent) ⇒ Object

:nodoc:



56
57
58
# File 'lib/aclatraz/acl.rb', line 56

def clone(parent) # :nodoc:
  self.class.new(parent)
end

#deny(permission) ⇒ Object

Add permission for objects which don’t have given role.

Examples

deny :admin
deny :owner_of => "object"
deny :owner_of => :object
deny :owner_of => object
deny :manager_of => ClassName
deny all


37
38
39
# File 'lib/aclatraz/acl.rb', line 37

def deny(permission)
  @permissions[permission] = false
end

#on(*args, &block) ⇒ Object

See Aclatraz::ACL#on.



52
53
54
# File 'lib/aclatraz/acl.rb', line 52

def on(*args, &block)
  @parent.on(*args, &block)
end