Class: RbacCore::PermissionSet
- Inherits:
-
OptionsModel::Base
- Object
- OptionsModel::Base
- RbacCore::PermissionSet
- Defined in:
- lib/rbac_core/permission_set.rb
Class Method Summary collapse
- .draw(**constraints, &block) ⇒ Object
- .i18n_scope ⇒ Object
- .permission_class ⇒ Object
- .permission_class=(klass) ⇒ Object
- .register_permission(name, default = false, **options, &block) ⇒ Object
- .registered_permissions ⇒ Object
Instance Method Summary collapse
Class Method Details
.draw(**constraints, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/rbac_core/permission_set.rb', line 35 def draw(**constraints, &block) unless block_given? raise ArgumentError, "must provide a block" end Mapper.new(self, constraints).instance_exec(&block) self end |
.i18n_scope ⇒ Object
19 20 21 |
# File 'lib/rbac_core/permission_set.rb', line 19 def i18n_scope :rbac_core end |
.permission_class ⇒ Object
23 24 25 |
# File 'lib/rbac_core/permission_set.rb', line 23 def @permission_class || RbacCore. end |
.permission_class=(klass) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rbac_core/permission_set.rb', line 27 def (klass) unless klass && klass < Permission raise ArgumentError, "#{klass} should be sub-class of #{Permission}." end @permission_class = klass end |
.register_permission(name, default = false, **options, &block) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rbac_core/permission_set.rb', line 49 def (name, default = false, **, &block) raise ArgumentError, "`name` can't be blank" if name.blank? attribute name, :boolean, default: default [name] = .new name, , &block end |
.registered_permissions ⇒ Object
45 46 47 |
# File 'lib/rbac_core/permission_set.rb', line 45 def @registered_permissions ||= ActiveSupport::HashWithIndifferentAccess.new end |
Instance Method Details
#permitted_permission_names ⇒ Object
5 6 7 |
# File 'lib/rbac_core/permission_set.rb', line 5 def attributes.select { |_, v| v }.keys end |
#permitted_permissions(include_nested: true) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/rbac_core/permission_set.rb', line 9 def (include_nested: true) = self.class..slice(*).values if include_nested && nested_attributes.any? .concat nested_attributes.values.map(&:permitted_permissions).flatten! end ComputedPermissions.new() end |