Class: Access::Role
- Inherits:
-
Object
- Object
- Access::Role
- 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
-
#description ⇒ Object
readonly
The description of the role.
-
#id ⇒ Object
readonly
The record-id.
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.
-
#storable ⇒ Object
:nodoc: serialize to column => value for storage.
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
#description ⇒ Object (readonly)
The description of the role
50 51 52 |
# File 'lib/access/role.rb', line 50 def description @description end |
#id ⇒ Object (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)
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:
82 83 84 |
# File 'lib/access/role.rb', line 82 def eql?(other) self.class == other.class && @id.eql?(other.id) end |
#hash ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/access/role.rb', line 87 def hash @id.hash end |
#storable ⇒ Object
: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 |