Class: Aclatraz::Suspect::Roles

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

Direct Known Subclasses

SemanticRoles::Base

Constant Summary collapse

ACL_ROLE_SUFFIXES =

These suffixes will be ignored while checking permission.

/(_(of|at|on|by|for|in))?\Z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suspect) ⇒ Roles

:nodoc:



10
11
12
# File 'lib/aclatraz/suspect.rb', line 10

def initialize(suspect) # :nodoc:
  @suspect = suspect
end

Instance Attribute Details

#suspectObject (readonly)

Permissions will be checked for this object.



8
9
10
# File 'lib/aclatraz/suspect.rb', line 8

def suspect
  @suspect
end

Instance Method Details

#allObject Also known as: list

Returns list of roles assigned to current object.

Examples

suspect.roles.assign(:foo)
suspect.roles.assign(:bar)
suspect.roles.all # => ["foo", "bar"]


59
60
61
# File 'lib/aclatraz/suspect.rb', line 59

def all
  Aclatraz.store.roles(self)
end

#assign(role, object = nil) ⇒ Object Also known as: add, append

Assigns given role to current object.

Examples

suspect.roles.has?(:foo) # => false
suspect.roles.assign(:foo)
suspect.roles.has?(:foo) # => true


33
34
35
# File 'lib/aclatraz/suspect.rb', line 33

def assign(role, object=nil)
  Aclatraz.store.set(role.to_s.gsub(ACL_ROLE_SUFFIXES, ''), suspect, object)
end

#delete(role, object = nil) ⇒ Object Also known as: remove

Removes given role from current object.

Examples

suspect.roles.assign(:foo)
suspect.roles.has?(:foo) # => true
suspect.roles.delete(:foo)
suspect.roles.has?(:foo) # => false


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

def delete(role, object=nil)
  Aclatraz.store.delete(role.to_s.gsub(ACL_ROLE_SUFFIXES, ''), suspect, object)
end

#has?(role, object = nil) ⇒ Boolean Also known as: check?

Check if current object has assigned given role.

Examples

suspect.roles.assign(:foo)
suspect.roles.has?(:foo) # => true
suspect.roles.has?(:bar) # => false

Returns:

  • (Boolean)


21
22
23
# File 'lib/aclatraz/suspect.rb', line 21

def has?(role, object=nil)
  Aclatraz.store.check(role.to_s.gsub(ACL_ROLE_SUFFIXES, ''), suspect, object)
end