Class: DoRole::PermissionSetManager
- Inherits:
-
Object
- Object
- DoRole::PermissionSetManager
- Defined in:
- lib/do_role/permission_set_manager.rb
Instance Method Summary collapse
- #for_namespace(namespace) ⇒ Object
-
#initialize ⇒ PermissionSetManager
constructor
A new instance of PermissionSetManager.
- #namespace_exists?(namespace) ⇒ Boolean
- #namespaces ⇒ Object
- #permissions_for(namespace) ⇒ Object
- #remove_namespace(namespace) ⇒ Object
- #set_inheritance(namespace, inherit_from) ⇒ Object
- #valid_permission?(namespace, permission_name) ⇒ Boolean
Constructor Details
#initialize ⇒ PermissionSetManager
Returns a new instance of PermissionSetManager.
7 8 9 |
# File 'lib/do_role/permission_set_manager.rb', line 7 def initialize @permission_sets = {}.with_indifferent_access end |
Instance Method Details
#for_namespace(namespace) ⇒ Object
11 12 13 |
# File 'lib/do_role/permission_set_manager.rb', line 11 def for_namespace(namespace) @permission_sets[namespace.to_s] ||= PermissionSet.new end |
#namespace_exists?(namespace) ⇒ Boolean
19 20 21 |
# File 'lib/do_role/permission_set_manager.rb', line 19 def namespace_exists?(namespace) @permission_sets.key?(namespace.to_s) end |
#namespaces ⇒ Object
15 16 17 |
# File 'lib/do_role/permission_set_manager.rb', line 15 def namespaces @permission_sets.keys end |
#permissions_for(namespace) ⇒ Object
27 28 29 |
# File 'lib/do_role/permission_set_manager.rb', line 27 def (namespace) @permission_sets[namespace.to_s].try(:permissions) || {} end |
#remove_namespace(namespace) ⇒ Object
23 24 25 |
# File 'lib/do_role/permission_set_manager.rb', line 23 def remove_namespace(namespace) @permission_sets.delete(namespace.to_s) end |
#set_inheritance(namespace, inherit_from) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/do_role/permission_set_manager.rb', line 35 def set_inheritance(namespace, inherit_from) target_set = for_namespace(namespace) Array(inherit_from).each do |parent_namespace| if (parent_set = @permission_sets[parent_namespace]) target_set..deep_merge!(parent_set.) end end end |
#valid_permission?(namespace, permission_name) ⇒ Boolean
31 32 33 |
# File 'lib/do_role/permission_set_manager.rb', line 31 def (namespace, ) @permission_sets[namespace.to_s].try(:valid_permission?, ) end |