Class: Access::Role

Inherits:
Object
  • Object
show all
Includes:
Savable
Defined in:
lib/access/role.rb,
lib/access/role/base.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

Attributes included from Savable

#access, #base

Instance Method Summary collapse

Methods included from Savable

#delete, #save

Constructor Details

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

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



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

def initialize(role, description=nil, other={})
	@oid         = role
	@privileges  = PrivilegeList.new(self, other[:privileges])
	@roles       = RoleList.new(self, other[:roles])
	@description = (description || "No description").freeze
end

Instance Attribute Details

#descriptionObject

The description of the role



25
26
27
# File 'lib/access/role.rb', line 25

def description
  @description
end

#oidObject (readonly)

The record-oid



22
23
24
# File 'lib/access/role.rb', line 22

def oid
  @oid
end

#privilegesObject (readonly)

Privileges this role has granted



31
32
33
# File 'lib/access/role.rb', line 31

def privileges
  @privileges
end

#rolesObject (readonly)

The roles this role belongs to



28
29
30
# File 'lib/access/role.rb', line 28

def roles
  @roles
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)


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

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


69
70
71
# File 'lib/access/role.rb', line 69

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

#hashObject

:nodoc:



74
75
76
# File 'lib/access/role.rb', line 74

def hash
	@oid.hash
end

#inspectObject

:nodoc:



78
79
80
81
82
83
84
85
86
# File 'lib/access/role.rb', line 78

def inspect # :nodoc:
	"#<%s:0x%08x description=%s privileges=%s roles=%s>" %  [
		self.class,
		object_id << 1,
		@description,
		@privileges.inspect,
		@roles.inspect,
	]
end

#storableObject

:nodoc: serialize to column => value for storage



52
53
54
55
56
57
58
59
# File 'lib/access/role.rb', line 52

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