lib/kanri/kanri.rb
# Identifies if the role allows the given `user` to perform the
# specified `action` on the given `target`.
#
# == Algorithm
#
# The order of operations is as follows:
#
#   1. Check if the target is a class for which the role has
#      permissions.
#   2. Check if the action is covered by permissions for the target
#      class.
#   3. Check if any of the matching permissions allow the given
#      user to act on the specific target object.
# @param user [Object] the user performing the action
# @param action [Symbol] the action being performed
# @param target [Object] the target of the action
# @return [Boolean] whether the `user` has permission to perform the
#   `action` on the `target`


Algorithm

The order of operations is as follows.

1. Check if the target is a class for which the role has
permissions.
2. Check if the action is covered by permissions for the target
class.
3. Check if any of the matching permissions allow the given
user to act on the specific target object.
Algorithm The order of operations is as follows . 1 . Check if the target is a class for which the role has permissions . 2 . Check if the action is covered by permissions for the target class . 3 . Check if any of the matching permissions allow the given user to act on the specific target object .
def can?(user, action, target)
            @permissions.select { |cls, _| target.is_a?(cls) || target == cls }
                        .collect { |_, perms| perms }
                        .flatten
                        .select { |perm| perm.has_action? action }
                        .any? { |perm| perm.allow? user, target }
        end
def can? ( user , action , target ) @permissions . select { | cls , _ | target . is_a? ( cls ) || target == cls } . collect { | _ , perms | perms } . flatten . select { | perm | perm . has_action? action } . any? { | perm | perm . allow? user , target } end
Identifies if the role allows the given `user` to perform the
specified `action` on the given `target`.
Identifies if the role allows the given ` user ` to perform the specified ` action ` on the given ` target ` .
whether the `user` has permission to perform the `action` on the `target`
whether the ` user ` has permission to perform the ` action ` on the ` target `
Boolean
user
the user performing the action
the user performing the action
action
the action being performed
the action being performed
target
the target of the action
the target of the action