module Pundit
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/generators/pundit/install/install_generator.rbs module Pundit def policy: (User user, User record) -> nil def pundit_model: (Trade record) -> Trade end
def self.included(base)
def self.included(base) location = caller_locations(1, 1).first warn <<~WARNING 'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead. (called from #{location.label} at #{location.path}:#{location.lineno}) WARNING base.include Authorization end
def authorize(user, possibly_namespaced_record, query, policy_class: nil, cache: {})
-
(Object)
- Always returns the passed object record
Raises:
-
(NotAuthorizedError)
- if the given query method returned false
Parameters:
-
cache
(#[], #[]=
) -- a Hash-like object to cache the found policy instance in -
policy_class
(Class
) -- the policy class we want to force use of -
query
(Symbol, String
) -- the predicate method to check on the policy (e.g. `:show?`) -
possibly_namespaced_record
(Object, Array
) -- the object we're checking permissions of -
user
(Object
) -- the user that initiated the action
def authorize(user, possibly_namespaced_record, query, policy_class: nil, cache: {}) record = pundit_model(possibly_namespaced_record) policy = if policy_class policy_class.new(user, record) else cache[possibly_namespaced_record] ||= policy!(user, possibly_namespaced_record) end raise NotAuthorizedError, query: query, record: record, policy: policy unless policy.public_send(query) record end
def policy(user, record)
Experimental RBS support (using type sampling data from the type_fusion
project).
def policy: (User user, User record) -> nil
This signature was generated using 1 sample from 1 application.
-
(Object, nil)
- instance of policy class with query methods
Raises:
-
(InvalidConstructorError)
- if the policy constructor called incorrectly
Parameters:
-
record
(Object
) -- the object we're retrieving the policy for -
user
(Object
) -- the user that initiated the action
Other tags:
- See: https://github.com/varvet/pundit#policies -
def policy(user, record) policy = PolicyFinder.new(record).policy policy&.new(user, pundit_model(record)) rescue ArgumentError raise InvalidConstructorError, "Invalid #<#{policy}> constructor is called" end
def policy!(user, record)
-
(Object)
- instance of policy class with query methods
Raises:
-
(InvalidConstructorError)
- if the policy constructor called incorrectly -
(NotDefinedError)
- if the policy cannot be found
Parameters:
-
record
(Object
) -- the object we're retrieving the policy for -
user
(Object
) -- the user that initiated the action
Other tags:
- See: https://github.com/varvet/pundit#policies -
def policy!(user, record) policy = PolicyFinder.new(record).policy! policy.new(user, pundit_model(record)) rescue ArgumentError raise InvalidConstructorError, "Invalid #<#{policy}> constructor is called" end
def policy_scope(user, scope)
-
(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
def policy_scope!(user, scope)
-
(Scope{#resolve})
- instance of scope class which can resolve to a scope
Raises:
-
(InvalidConstructorError)
- if the policy constructor called incorrectly -
(NotDefinedError)
- if the policy scope cannot be found
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
def pundit_model(record)
Experimental RBS support (using type sampling data from the type_fusion
project).
def pundit_model: (Trade record) -> Trade
This signature was generated using 1 sample from 1 application.
def pundit_model(record) record.is_a?(Array) ? record.last : record end