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
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #allows?(privilege, condition = nil) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(role, description = nil, other = {}) ⇒ Role
constructor
A new instance of Role.
- #storable ⇒ Object
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
39 40 41 |
# File 'lib/access/role.rb', line 39 def description @description end |
#id ⇒ Object (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
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
61 62 63 |
# File 'lib/access/role.rb', line 61 def eql?(other) self.class == other.class && @id.eql?(other.id) end |
#hash ⇒ Object
65 66 67 |
# File 'lib/access/role.rb', line 65 def hash @id.hash end |
#storable ⇒ Object
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 |