class Corral::SubjectRule

Rule class representing actions doable on a subject. @!visibility private

Public Class Methods

new() click to toggle source
# File lib/corral/rule.rb, line 5
def initialize
  @actions = {}
end

Public Instance Methods

add_deny(action, block) click to toggle source

Add a denying ACL for a particular action.

@param action [symbol] The action. @param block An optional block for granularity.

# File lib/corral/rule.rb, line 21
def add_deny(action, block)
  @actions[action] = (block || false)
end
add_grant(action, block) click to toggle source

Add a granting ACL for a particular action.

@param action [symbol] The action. @param block An optional block for granularity.

# File lib/corral/rule.rb, line 13
def add_grant(action, block)
  @actions[action] = (block || true)
end
authorized?(action, subject, args) click to toggle source

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.

# File lib/corral/rule.rb, line 30
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