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.
19 20 21 |
# File 'lib/ddr/auth/roles/role_set.rb', line 19 def initialize(role_set) @role_set = role_set end |
Instance Attribute Details
#role_set ⇒ Object (readonly)
Returns the value of attribute role_set.
11 12 13 |
# File 'lib/ddr/auth/roles/role_set.rb', line 11 def role_set @role_set end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/ddr/auth/roles/role_set.rb', line 79 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
35 36 37 |
# File 'lib/ddr/auth/roles/role_set.rb', line 35 def grant(*roles) raise NotImplementedError, "Subclasses must implement `grant`." end |
#granted ⇒ Object
23 24 25 26 27 |
# File 'lib/ddr/auth/roles/role_set.rb', line 23 def granted warn "[DEPRECATION] `granted` is deprecated." \ " Use the RoleSet object directly (#{caller.first})." self end |
#granted?(role) ⇒ Boolean
Return true/false depending on whether the role has been granted
42 43 44 |
# File 'lib/ddr/auth/roles/role_set.rb', line 42 def granted?(role) include? coerce(role) end |
#replace(*roles) ⇒ Object
Replace the current roles in the role set with new roles
56 57 58 59 |
# File 'lib/ddr/auth/roles/role_set.rb', line 56 def replace(*roles) revoke_all grant(*roles) end |
#revoke(*roles) ⇒ Object
Revokes roles - i.e., removes them from the role set
50 51 52 |
# File 'lib/ddr/auth/roles/role_set.rb', line 50 def revoke(*roles) raise NotImplementedError, "Subclasses must implement `revoke`." end |
#revoke_all ⇒ RoleSet
Remove all roles from the role set
63 64 65 |
# File 'lib/ddr/auth/roles/role_set.rb', line 63 def revoke_all raise NotImplementedError, "Subclasses must implement `revoke_all`." end |
#serialize ⇒ Array<Hash>
Return the RoleSet serialized as an Array of serialized Roles
75 76 77 |
# File 'lib/ddr/auth/roles/role_set.rb', line 75 def serialize to_a.map(&:serialize) end |
#to_json ⇒ String
Return the RoleSet serialized as JSON
69 70 71 |
# File 'lib/ddr/auth/roles/role_set.rb', line 69 def to_json serialize.to_json end |