Class: Ddr::Auth::Roles::RoleSet Abstract
- Inherits:
-
Object
- Object
- Ddr::Auth::Roles::RoleSet
- Includes:
- Enumerable
- Defined in:
- lib/ddr/auth/roles/role_set.rb
Overview
Wraps a set of Roles
Direct Known Subclasses
Instance Attribute Summary collapse
-
#role_set ⇒ Object
readonly
Returns the value of attribute role_set.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#grant(*roles) ⇒ Object
Grants roles - i.e., adds them to the role set.
- #granted ⇒ Object
-
#granted?(role) ⇒ Boolean
Return true/false depending on whether the role has been granted.
-
#initialize(role_set) ⇒ RoleSet
constructor
A new instance of RoleSet.
-
#replace(*roles) ⇒ Object
Replace the current roles in the role set with new roles.
-
#revoke(*roles) ⇒ Object
Revokes roles - i.e., removes them from the role set.
-
#revoke_all ⇒ RoleSet
Remove all roles from the role set.
-
#serialize ⇒ Array<Hash>
Return the RoleSet serialized as an Array of serialized Roles.
-
#to_json ⇒ String
Return the RoleSet serialized as JSON.
Constructor Details
#initialize(role_set) ⇒ RoleSet
Returns a new instance of RoleSet.
20 21 22 |
# File 'lib/ddr/auth/roles/role_set.rb', line 20 def initialize(role_set) @role_set = role_set end |
Instance Attribute Details
#role_set ⇒ Object (readonly)
Returns the value of attribute role_set.
12 13 14 |
# File 'lib/ddr/auth/roles/role_set.rb', line 12 def role_set @role_set end |
Instance Method Details
#==(other) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/ddr/auth/roles/role_set.rb', line 80 def ==(other) if other.is_a? RoleSet self.to_set == other.to_set else super end end |
#grant(*roles) ⇒ Object
Grants roles - i.e., adds them to the role set
36 37 38 |
# File 'lib/ddr/auth/roles/role_set.rb', line 36 def grant(*roles) raise NotImplementedError, "Subclasses must implement `grant`." end |
#granted ⇒ Object
24 25 26 27 28 |
# File 'lib/ddr/auth/roles/role_set.rb', line 24 def granted Deprecation.warn(self.class, "`granted` is deprecated." \ " Use the RoleSet object directly.") self end |
#granted?(role) ⇒ Boolean
Return true/false depending on whether the role has been granted
43 44 45 |
# File 'lib/ddr/auth/roles/role_set.rb', line 43 def granted?(role) include? coerce(role) end |
#replace(*roles) ⇒ Object
Replace the current roles in the role set with new roles
57 58 59 60 |
# File 'lib/ddr/auth/roles/role_set.rb', line 57 def replace(*roles) revoke_all grant(*roles) end |
#revoke(*roles) ⇒ Object
Revokes roles - i.e., removes them from the role set
51 52 53 |
# File 'lib/ddr/auth/roles/role_set.rb', line 51 def revoke(*roles) raise NotImplementedError, "Subclasses must implement `revoke`." end |
#revoke_all ⇒ RoleSet
Remove all roles from the role set
64 65 66 |
# File 'lib/ddr/auth/roles/role_set.rb', line 64 def revoke_all raise NotImplementedError, "Subclasses must implement `revoke_all`." end |
#serialize ⇒ Array<Hash>
Return the RoleSet serialized as an Array of serialized Roles
76 77 78 |
# File 'lib/ddr/auth/roles/role_set.rb', line 76 def serialize to_a.map(&:serialize) end |
#to_json ⇒ String
Return the RoleSet serialized as JSON
70 71 72 |
# File 'lib/ddr/auth/roles/role_set.rb', line 70 def to_json serialize.to_json end |