Class: Ddr::Auth::Roles::RoleSet
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ddr::Auth::Roles::RoleSet
- Defined in:
- lib/ddr/auth/roles/role_set.rb
Overview
Wraps a set of Roles (ActiveTriples::Term)
Instance Method Summary collapse
-
#grant(*roles) ⇒ Object
Grants roles - i.e., adds them to the role set Note that we reject roles that are included because ActiveTriples::Term#<< does not support isomorphism.
-
#granted?(role) ⇒ Boolean
Return true/false depending on whether the role has been granted.
-
#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 Note that we have to destroy resources on the ActiveTriples::Term because Term#delete does not support isomorphism.
-
#revoke_all ⇒ Object
Remove all roles from the role set.
- #to_a ⇒ Object
- #where(criteria) ⇒ Object
Instance Method Details
#grant(*roles) ⇒ Object
Grants roles - i.e., adds them to the role set
Note that we reject roles that are included because
ActiveTriples::Term#<< does not support isomorphism.
https://github.com/ActiveTriples/ActiveTriples/issues/42
20 21 22 |
# File 'lib/ddr/auth/roles/role_set.rb', line 20 def grant(*roles) self << coerce(roles).reject { |r| include?(r) } end |
#granted?(role) ⇒ Boolean
Return true/false depending on whether the role has been granted
27 28 29 |
# File 'lib/ddr/auth/roles/role_set.rb', line 27 def granted?(role) include? coerce(role) end |
#replace(*roles) ⇒ Object
Replace the current roles in the role set with new roles
49 50 51 52 53 |
# File 'lib/ddr/auth/roles/role_set.rb', line 49 def replace(*roles) revoke_all # XXX Not sure why we have to use __getobj__ here __getobj__.set coerce(roles) end |
#revoke(*roles) ⇒ Object
Revokes roles - i.e., removes them from the role set
Note that we have to destroy resources on the
ActiveTriples::Term because Term#delete does not
support isomorphism.
https://github.com/ActiveTriples/ActiveTriples/issues/42
39 40 41 42 43 44 45 |
# File 'lib/ddr/auth/roles/role_set.rb', line 39 def revoke(*roles) coerce(roles).each do |role| if role_index = find_index(role) self[role_index].destroy end end end |
#revoke_all ⇒ Object
Remove all roles from the role set
56 57 58 |
# File 'lib/ddr/auth/roles/role_set.rb', line 56 def revoke_all delete(*__getobj__) end |
#to_a ⇒ Object
60 61 62 |
# File 'lib/ddr/auth/roles/role_set.rb', line 60 def to_a map.to_a end |
#where(criteria) ⇒ Object
64 65 66 |
# File 'lib/ddr/auth/roles/role_set.rb', line 64 def where(criteria) query.where(criteria) end |