module Pundit

def policy_scope(user, scope)

Returns:
  • (Scope{#resolve}, nil) - instance of scope class which can resolve to a scope

Raises:
  • (InvalidConstructorError) - if the policy constructor called incorrectly

Parameters:
  • scope (Object) -- the object we're retrieving the policy scope for
  • user (Object) -- the user that initiated the action

Other tags:
    See: https://github.com/varvet/pundit#scopes -
def policy_scope(user, scope)
  policy_scope_class = PolicyFinder.new(scope).scope
  return unless policy_scope_class
  begin
    policy_scope = policy_scope_class.new(user, pundit_model(scope))
  rescue ArgumentError
    raise InvalidConstructorError, "Invalid #<#{policy_scope_class}> constructor is called"
  end
  policy_scope.resolve
end