class Decidim::PermissionsRegistry
Takes care of holding and accessing permissions classes for each artifact.
Public Class Methods
chain_for(artifact)
click to toggle source
Syntactic sugar for the `chain_for` instance method.
# File lib/decidim/permissions_registry.rb, line 13 def self.chain_for(artifact) ::Decidim.permissions_registry.chain_for(artifact) end
new()
click to toggle source
# File lib/decidim/permissions_registry.rb, line 8 def initialize @registry = {} end
Public Instance Methods
artifact_to_key(artifact)
click to toggle source
Registry accepts the class or the class name of the artifact, but the registry only indexes by the name. Artifact name normalization is done here.
# File lib/decidim/permissions_registry.rb, line 35 def artifact_to_key(artifact) artifact.respond_to?(:name) ? artifact.name : artifact end
chain_for(artifact)
click to toggle source
Returns the registered array of permissions for the given `artifact`.
artifact
is expected to be the class or module that declares `NeedsPermission.permission_class_chain`.
# File lib/decidim/permissions_registry.rb, line 20 def chain_for(artifact) @registry[artifact_to_key(artifact)] end
register_permissions(artifact, *permission_classes)
click to toggle source
Registers the of `Permissions` for the given `artifact`.
artifact
is expected to be the class or module that declares `NeedsPermission.permission_class_chain`. permission_classes
are subclasses of `DefaultPermissions`.
# File lib/decidim/permissions_registry.rb, line 28 def register_permissions(artifact, *permission_classes) @registry[artifact_to_key(artifact)] = permission_classes.dup end