Class: Access::Role
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
-
#description ⇒ Object
The description of the role.
-
#id ⇒ Object
readonly
The record-id.
-
#privileges ⇒ Object
readonly
Privileges this role has granted.
-
#roles ⇒ Object
readonly
The roles this role belongs to.
Attributes included from Savable
Instance Method Summary collapse
-
#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).
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(role, description = nil, other = {}) ⇒ Role
constructor
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.
-
#inspect ⇒ Object
:nodoc:.
-
#storable ⇒ Object
:nodoc: serialize to column => value for storage.
Methods included from Savable
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
63 64 65 66 67 68 |
# File 'lib/access/role.rb', line 63 def initialize(role, description=nil, other={}) @id = role @privileges = Privileges.new(self, other[:privileges]) @roles = Roles.new(self, other[:roles]) @description = (description || "No description").freeze end |
Instance Attribute Details
#description ⇒ Object
The description of the role
51 52 53 |
# File 'lib/access/role.rb', line 51 def description @description end |
#id ⇒ Object (readonly)
The record-id
48 49 50 |
# File 'lib/access/role.rb', line 48 def id @id end |
#privileges ⇒ Object (readonly)
Privileges this role has granted
57 58 59 |
# File 'lib/access/role.rb', line 57 def privileges @privileges end |
#roles ⇒ Object (readonly)
The roles this role belongs to
54 55 56 |
# File 'lib/access/role.rb', line 54 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)
90 91 92 |
# File 'lib/access/role.rb', line 90 def allows?(privilege, condition=nil) @privileges.allow?(privilege, condition) || @roles.allow?(privilege, condition) end |
#eql?(other) ⇒ Boolean
:nodoc:
95 96 97 |
# File 'lib/access/role.rb', line 95 def eql?(other) self.class == other.class && @id.eql?(other.id) end |
#hash ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/access/role.rb', line 100 def hash @id.hash end |
#inspect ⇒ Object
:nodoc:
104 105 106 107 108 109 110 111 112 |
# File 'lib/access/role.rb', line 104 def inspect # :nodoc: "#<%s:0x%08x description=%s privileges=%s roles=%s>" % [ self.class, object_id << 1, @description, @privileges.inspect, @roles.inspect, ] end |
#storable ⇒ Object
:nodoc: serialize to column => value for storage
78 79 80 81 82 83 84 85 |
# File 'lib/access/role.rb', line 78 def storable { :id => @id, :description => @description, :privileges => @privileges.storable, :roles => @roles.storable, } end |