Sha256: bbf9f704acaaedf49f4229deda17367229004f995e2469bf372d8bb856e373b1
Contents?: true
Size: 1.29 KB
Versions: 5
Compression:
Stored size: 1.29 KB
Contents
module Corral # Rule class representing actions doable on a subject. # @!visibility private class SubjectRule def initialize @actions = {} end # Add a granting ACL for a particular action. # # @param action [symbol] The action. # @param block An optional block for granularity. def add_grant(action, block) @actions[action] = (block || true) end # Add a denying ACL for a particular action. # # @param action [symbol] The action. # @param block An optional block for granularity. def add_deny(action, block) @actions[action] = (block || false) end # Return whether or not an object can perform a particular action on a subject # @param action [Symbol] The action. # @param subject [Object] The subject. # @param args [Hash] Variable arguments for more granular matching. # @return [Boolean] True or false. def authorized?(action, subject, args) block = @actions[:manage] || @actions[action] return false unless block return true if block == true return !!block.call(*[subject, *args]) end end # Fake rule representing nothing matched a subject when looking up its ability. # @!visibility private class NullRule # :nodoc: def self.authorized?(*) false end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
corral_acl-1.0.1 | lib/corral/rule.rb |
corral_acl-1.0.0 | lib/corral/rule.rb |
corral_acl-0.9.9 | lib/corral/rule.rb |
corral_acl-0.9.1 | lib/corral/rule.rb |
corral_acl-0.9.0 | lib/corral/rule.rb |