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

Create a new Role role is a role-id, should be w+ description is a piece of text describing the role other: a hash that accepts the keys :privileges and :roles



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

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)

The description of the role



50
51
52
# File 'lib/access/role.rb', line 50

def description
  @description
end

#idObject (readonly)

The record-id



47
48
49
# File 'lib/access/role.rb', line 47

def id
  @id
end

Instance Method Details

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

recursively tests the role and its contained roles if any of them allows a given privilege under given conditions (may be nil to indicate no condition)

Returns:

  • (Boolean)


77
78
79
# File 'lib/access/role.rb', line 77

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


82
83
84
# File 'lib/access/role.rb', line 82

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

#hashObject

:nodoc:



87
88
89
# File 'lib/access/role.rb', line 87

def hash
	@id.hash
end

#storableObject

:nodoc: serialize to column => value for storage



65
66
67
68
69
70
71
72
# File 'lib/access/role.rb', line 65

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