Class: Access::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/access/role.rb

Overview

Access::Role’s are a set of privileges with (optionally) an additional restriction (which is applied globally).

Defined Under Namespace

Modules: Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, description = nil, other = {}) ⇒ Role

Returns a new instance of Role.



41
42
43
44
45
46
# File 'lib/access/role.rb', line 41

def initialize(role, description=nil, other={})
	@id          = role
	@privileges  = Privileges.new(self, other[:privileges])
	@roles       = Roles.new(self, other[:roles])
	@description = description || "No description"
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



39
40
41
# File 'lib/access/role.rb', line 39

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



38
39
40
# File 'lib/access/role.rb', line 38

def id
  @id
end

Instance Method Details

#allows?(privilege, condition = nil) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/access/role.rb', line 57

def allows?(privilege, condition=nil)
	@privileges.allow?(privilege, condition) || @roles.allow?(privilege, condition)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/access/role.rb', line 61

def eql?(other)
	self.class == other.class && @id.eql?(other.id)
end

#hashObject



65
66
67
# File 'lib/access/role.rb', line 65

def hash
	@id.hash
end

#storableObject



48
49
50
51
52
53
54
55
# File 'lib/access/role.rb', line 48

def storable
	{
		:id          => @id,
		:description => @description,
		:privileges  => @privileges.storable,
		:roles       => @roles.storable,
	}
end