Class: Access::Roles
Overview
A list of roles
Instance Method Summary collapse
-
#add(role) ⇒ Object
add a role (Role instance).
-
#allow?(privilege, condition = nil) ⇒ Boolean
Tests if any of the roles in self allows a privilege under given conditions (may be nil to indicate no condition).
-
#delete(role) ⇒ Object
delete a role (Role instance).
-
#each(&block) ⇒ Object
Iterate over the roles.
-
#initialize(owner, roles = nil) ⇒ Roles
constructor
owner must be capable of #save roles is the list of Role instances (array).
-
#inspect ⇒ Object
:nodoc:.
-
#list ⇒ Object
all roles.
-
#storable ⇒ Object
:nodoc: prepare for storage.
Methods included from Enumerable
Constructor Details
#initialize(owner, roles = nil) ⇒ Roles
owner must be capable of #save roles is the list of Role instances (array)
121 122 123 124 |
# File 'lib/access/role.rb', line 121 def initialize(owner, roles=nil) @owner = owner @roles = roles || [] end |
Instance Method Details
#add(role) ⇒ Object
add a role (Role instance)
133 134 135 136 |
# File 'lib/access/role.rb', line 133 def add(role) @roles << role @owner.save end |
#allow?(privilege, condition = nil) ⇒ Boolean
Tests if any of the roles in self allows a privilege under given conditions (may be nil to indicate no condition)
128 129 130 |
# File 'lib/access/role.rb', line 128 def allow?(privilege, condition=nil) @roles.any? { |role| role.allows?(privilege, condition) } end |
#delete(role) ⇒ Object
delete a role (Role instance)
139 140 141 142 |
# File 'lib/access/role.rb', line 139 def delete(role) @roles.delete(role) @owner.save end |
#each(&block) ⇒ Object
Iterate over the roles
150 151 152 |
# File 'lib/access/role.rb', line 150 def each(&block) @roles.each(&block) end |
#inspect ⇒ Object
:nodoc:
160 161 162 163 164 165 166 |
# File 'lib/access/role.rb', line 160 def inspect # :nodoc: "#<%s:0x%08x roles=%s>" % [ self.class, object_id << 1, @roles.map { |r| r.id }.join(', '), ] end |
#list ⇒ Object
all roles
145 146 147 |
# File 'lib/access/role.rb', line 145 def list @roles.dup end |
#storable ⇒ Object
:nodoc: prepare for storage
156 157 158 |
# File 'lib/access/role.rb', line 156 def storable @roles.map { |role| role.id } end |