openaustralia/planningalerts

View on GitHub
sorbet/rbi/gems/pundit@2.3.2.rbi

Summary

Maintainability
Test Coverage
# typed: true

# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `pundit` gem.
# Please instead update this file by running `bin/tapioca gem pundit`.


# @api public
#
# source://pundit//lib/pundit/version.rb#3
module Pundit
  include ::Pundit::Authorization

  class << self
    # @api public
    # @see [Pundit::Context#authorize]
    #
    # source://pundit//lib/pundit.rb#71
    def authorize(user, record, query, policy_class: T.unsafe(nil), cache: T.unsafe(nil)); end

    # @api public
    # @private
    #
    # source://pundit//lib/pundit.rb#60
    def included(base); end

    # @api public
    # @see [Pundit::Context#policy]
    #
    # source://pundit//lib/pundit.rb#92
    def policy(user, *args, **kwargs, &block); end

    # @api public
    # @see [Pundit::Context#policy!]
    #
    # source://pundit//lib/pundit.rb#97
    def policy!(user, *args, **kwargs, &block); end

    # @api public
    # @see [Pundit::Context#policy_scope]
    #
    # source://pundit//lib/pundit.rb#82
    def policy_scope(user, *args, **kwargs, &block); end

    # @api public
    # @see [Pundit::Context#policy_scope!]
    #
    # source://pundit//lib/pundit.rb#87
    def policy_scope!(user, *args, **kwargs, &block); end
  end
end

# source://pundit//lib/pundit/authorization.rb#4
module Pundit::Authorization
  extend ::ActiveSupport::Concern

  protected

  # Retrieves the policy for the given record, initializing it with the record
  # and current user and finally throwing an error if the user is not
  # authorized to perform the given action.
  #
  # @param record [Object, Array] the object we're checking permissions of
  # @param query [Symbol, String] the predicate method to check on the policy (e.g. `:show?`).
  #   If omitted then this defaults to the Rails controller action name.
  # @param policy_class [Class] the policy class we want to force use of
  # @raise [NotAuthorizedError] if the given query method returned false
  # @return [Object] Always returns the passed object record
  #
  # source://pundit//lib/pundit/authorization.rb#70
  def authorize(record, query = T.unsafe(nil), policy_class: T.unsafe(nil)); end

  # Retrieves a set of permitted attributes from the policy by instantiating
  # the policy class for the given record and calling `permitted_attributes` on
  # it, or `permitted_attributes_for_{action}` if `action` is defined. It then infers
  # what key the record should have in the params hash and retrieves the
  # permitted attributes from the params hash under that key.
  #
  # @param record [Object] the object we're retrieving permitted attributes for
  # @param action [Symbol, String] the name of the action being performed on the record (e.g. `:update`).
  #   If omitted then this defaults to the Rails controller action name.
  # @return [Hash{String => Object}] the permitted attributes
  # @see https://github.com/varvet/pundit#strong-parameters
  #
  # source://pundit//lib/pundit/authorization.rb#125
  def permitted_attributes(record, action = T.unsafe(nil)); end

  # Cache of policies. You should not rely on this method.
  #
  #
  # @api private
  #
  # source://pundit//lib/pundit/authorization.rb#147
  def policies; end

  # Retrieves the policy for the given record.
  #
  # @param record [Object] the object we're retrieving the policy for
  # @return [Object] instance of policy class with query methods
  # @see https://github.com/varvet/pundit#policies
  #
  # source://pundit//lib/pundit/authorization.rb#110
  def policy(record); end

  # Retrieves the policy scope for the given record.
  #
  # @param scope [Object] the object we're retrieving the policy scope for
  # @param policy_scope_class [Class] the policy scope class we want to force use of
  # @return [Scope{#resolve}, nil] instance of scope class which can resolve to a scope
  # @see https://github.com/varvet/pundit#scopes
  #
  # source://pundit//lib/pundit/authorization.rb#100
  def policy_scope(scope, policy_scope_class: T.unsafe(nil)); end

  # Cache of policy scope. You should not rely on this method.
  #
  #
  # @api private
  #
  # source://pundit//lib/pundit/authorization.rb#156
  def policy_scopes; end

  # @return [Pundit::Context] a new instance of {Pundit::Context} with the current user
  #
  # source://pundit//lib/pundit/authorization.rb#19
  def pundit; end

  # Retrieves the params for the given record.
  #
  # @param record [Object] the object we're retrieving params for
  # @return [ActionController::Parameters] the params
  #
  # source://pundit//lib/pundit/authorization.rb#139
  def pundit_params_for(record); end

  # @return [Boolean] whether authorization has been performed, i.e. whether
  #   one {#authorize} or {#skip_authorization} has been called
  #
  # source://pundit//lib/pundit/authorization.rb#28
  def pundit_policy_authorized?; end

  # @return [Boolean] whether policy scoping has been performed, i.e. whether
  #   one {#policy_scope} or {#skip_policy_scope} has been called
  #
  # source://pundit//lib/pundit/authorization.rb#34
  def pundit_policy_scoped?; end

  # Hook method which allows customizing which user is passed to policies and
  # scopes initialized by {#authorize}, {#policy} and {#policy_scope}.
  #
  # @return [Object] the user object to be used with pundit
  # @see https://github.com/varvet/pundit#customize-pundit-user
  #
  # source://pundit//lib/pundit/authorization.rb#166
  def pundit_user; end

  # Allow this action not to perform authorization.
  #
  # @return [void]
  # @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
  #
  # source://pundit//lib/pundit/authorization.rb#82
  def skip_authorization; end

  # Allow this action not to perform policy scoping.
  #
  # @return [void]
  # @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
  #
  # source://pundit//lib/pundit/authorization.rb#90
  def skip_policy_scope; end

  # Raises an error if authorization has not been performed, usually used as an
  # `after_action` filter to prevent programmer error in forgetting to call
  # {#authorize} or {#skip_authorization}.
  #
  # @raise [AuthorizationNotPerformedError] if authorization has not been performed
  # @return [void]
  # @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
  #
  # source://pundit//lib/pundit/authorization.rb#45
  def verify_authorized; end

  # Raises an error if policy scoping has not been performed, usually used as an
  # `after_action` filter to prevent programmer error in forgetting to call
  # {#policy_scope} or {#skip_policy_scope} in index actions.
  #
  # @raise [AuthorizationNotPerformedError] if policy scoping has not been performed
  # @return [void]
  # @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
  #
  # source://pundit//lib/pundit/authorization.rb#56
  def verify_policy_scoped; end

  private

  # source://pundit//lib/pundit/authorization.rb#172
  def pundit_policy_scope(scope); end
end

# Error that will be raised if a controller action has not called the
# `authorize` or `skip_authorization` methods.
#
# @api public
#
# source://pundit//lib/pundit.rb#51
class Pundit::AuthorizationNotPerformedError < ::Pundit::Error; end

# source://pundit//lib/pundit/cache_store/null_store.rb#4
module Pundit::CacheStore; end

# @api private
#
# source://pundit//lib/pundit/cache_store/legacy_store.rb#6
class Pundit::CacheStore::LegacyStore
  # @api private
  # @return [LegacyStore] a new instance of LegacyStore
  #
  # source://pundit//lib/pundit/cache_store/legacy_store.rb#7
  def initialize(hash = T.unsafe(nil)); end

  # @api private
  #
  # source://pundit//lib/pundit/cache_store/legacy_store.rb#11
  def fetch(user:, record:); end
end

# @api private
#
# source://pundit//lib/pundit/cache_store/null_store.rb#6
class Pundit::CacheStore::NullStore
  # @api private
  #
  # source://pundit//lib/pundit/cache_store/null_store.rb#13
  def fetch(*_arg0, **_arg1); end

  class << self
    # @api private
    #
    # source://pundit//lib/pundit/cache_store/null_store.rb#10
    def instance; end
  end
end

# source://pundit//lib/pundit/context.rb#4
class Pundit::Context
  # @return [Context] a new instance of Context
  #
  # source://pundit//lib/pundit/context.rb#5
  def initialize(user:, policy_cache: T.unsafe(nil)); end

  # Retrieves the policy for the given record, initializing it with the
  # record and user and finally throwing an error if the user is not
  # authorized to perform the given action.
  #
  # @param user [Object] the user that initiated the action
  # @param possibly_namespaced_record [Object, Array] the object we're checking permissions of
  # @param query [Symbol, String] the predicate method to check on the policy (e.g. `:show?`)
  # @param policy_class [Class] the policy class we want to force use of
  # @raise [NotAuthorizedError] if the given query method returned false
  # @return [Object] Always returns the passed object record
  #
  # source://pundit//lib/pundit/context.rb#25
  def authorize(possibly_namespaced_record, query:, policy_class:); end

  # Retrieves the policy for the given record.
  #
  # @param user [Object] the user that initiated the action
  # @param record [Object] the object we're retrieving the policy for
  # @raise [InvalidConstructorError] if the policy constructor called incorrectly
  # @return [Object, nil] instance of policy class with query methods
  # @see https://github.com/varvet/pundit#policies
  #
  # source://pundit//lib/pundit/context.rb#86
  def policy(record); end

  # Retrieves the policy for the given record. Raises if not found.
  #
  # @param user [Object] the user that initiated the action
  # @param record [Object] the object we're retrieving the policy for
  # @raise [NotDefinedError] if the policy cannot be found
  # @raise [InvalidConstructorError] if the policy constructor called incorrectly
  # @return [Object] instance of policy class with query methods
  # @see https://github.com/varvet/pundit#policies
  #
  # source://pundit//lib/pundit/context.rb#98
  def policy!(record); end

  # @api private
  #
  # source://pundit//lib/pundit/context.rb#13
  def policy_cache; end

  # Retrieves the policy scope for the given record.
  #
  # @param user [Object] the user that initiated the action
  # @param scope [Object] the object we're retrieving the policy scope for
  # @raise [InvalidConstructorError] if the policy constructor called incorrectly
  # @return [Scope{#resolve}, nil] instance of scope class which can resolve to a scope
  # @see https://github.com/varvet/pundit#scopes
  #
  # source://pundit//lib/pundit/context.rb#45
  def policy_scope(scope); end

  # Retrieves the policy scope for the given record. Raises if not found.
  #
  # @param user [Object] the user that initiated the action
  # @param scope [Object] the object we're retrieving the policy scope for
  # @raise [NotDefinedError] if the policy scope cannot be found
  # @raise [InvalidConstructorError] if the policy constructor called incorrectly
  # @return [Scope{#resolve}] instance of scope class which can resolve to a scope
  # @see https://github.com/varvet/pundit#scopes
  #
  # source://pundit//lib/pundit/context.rb#66
  def policy_scope!(scope); end

  # Returns the value of attribute user.
  #
  # source://pundit//lib/pundit/context.rb#10
  def user; end

  private

  # source://pundit//lib/pundit/context.rb#104
  def cached_find(record); end

  # source://pundit//lib/pundit/context.rb#119
  def policy_finder(record); end

  # source://pundit//lib/pundit/context.rb#123
  def pundit_model(record); end
end

# To avoid name clashes with common Error naming when mixing in Pundit,
# keep it here with compact class style definition.
#
# @api private
#
# source://pundit//lib/pundit.rb#18
class Pundit::Error < ::StandardError; end

# @api private
#
# source://pundit//lib/pundit.rb#25
module Pundit::Generators; end

# @api private
#
# source://pundit//lib/pundit.rb#103
module Pundit::Helper
  # @api private
  #
  # source://pundit//lib/pundit.rb#104
  def policy_scope(scope); end
end

# Error that will be raised if a policy or policy scope constructor is not called correctly.
#
# @api public
#
# source://pundit//lib/pundit.rb#47
class Pundit::InvalidConstructorError < ::Pundit::Error; end

# Error that will be raised when authorization has failed
#
# @api public
#
# source://pundit//lib/pundit.rb#28
class Pundit::NotAuthorizedError < ::Pundit::Error
  # @api public
  # @return [NotAuthorizedError] a new instance of NotAuthorizedError
  #
  # source://pundit//lib/pundit.rb#31
  def initialize(options = T.unsafe(nil)); end

  # @api public
  #
  # source://pundit//lib/pundit.rb#29
  def policy; end

  # @api public
  #
  # source://pundit//lib/pundit.rb#29
  def query; end

  # @api public
  #
  # source://pundit//lib/pundit.rb#29
  def record; end
end

# Error that will be raised if a policy or policy scope is not defined.
#
# @api public
#
# source://pundit//lib/pundit.rb#58
class Pundit::NotDefinedError < ::Pundit::Error; end

# Finds policy and scope classes for given object.
#
# @api public
# @example
#   user = User.find(params[:id])
#   finder = PolicyFinder.new(user)
#   finder.policy #=> UserPolicy
#   finder.scope #=> UserPolicy::Scope
#
# source://pundit//lib/pundit/policy_finder.rb#12
class Pundit::PolicyFinder
  # @api public
  # @param object [any] the object to find policy and scope classes for
  # @return [PolicyFinder] a new instance of PolicyFinder
  #
  # source://pundit//lib/pundit/policy_finder.rb#17
  def initialize(object); end

  # @api public
  #
  # source://pundit//lib/pundit/policy_finder.rb#13
  def object; end

  # @api public
  # @return [String] the name of the key this object would have in a params hash
  #
  # source://pundit//lib/pundit/policy_finder.rb#59
  def param_key; end

  # @api public
  # @example
  #   policy = finder.policy #=> UserPolicy
  #   policy.show? #=> true
  #   policy.update? #=> false
  # @return [nil, Class] policy class with query methods
  # @see https://github.com/varvet/pundit#policies
  #
  # source://pundit//lib/pundit/policy_finder.rb#38
  def policy; end

  # @api public
  # @raise [NotDefinedError] if policy could not be determined
  # @return [Class] policy class with query methods
  #
  # source://pundit//lib/pundit/policy_finder.rb#53
  def policy!; end

  # @api public
  # @example
  #   scope = finder.scope #=> UserPolicy::Scope
  #   scope.resolve #=> <#ActiveRecord::Relation ...>
  # @return [nil, Scope{#resolve}] scope class which can resolve to a scope
  # @see https://github.com/varvet/pundit#scopes
  #
  # source://pundit//lib/pundit/policy_finder.rb#27
  def scope; end

  # @api public
  # @raise [NotDefinedError] if scope could not be determined
  # @return [Scope{#resolve}] scope class which can resolve to a scope
  #
  # source://pundit//lib/pundit/policy_finder.rb#46
  def scope!; end

  private

  # @api public
  #
  # source://pundit//lib/pundit/policy_finder.rb#73
  def find(subject); end

  # @api public
  #
  # source://pundit//lib/pundit/policy_finder.rb#89
  def find_class_name(subject); end
end

# Error that will be raised if a controller action has not called the
# `policy_scope` or `skip_policy_scope` methods.
#
# @api public
#
# source://pundit//lib/pundit.rb#55
class Pundit::PolicyScopingNotPerformedError < ::Pundit::AuthorizationNotPerformedError; end

# @api public
#
# source://pundit//lib/pundit.rb#22
Pundit::SUFFIX = T.let(T.unsafe(nil), String)

# source://pundit//lib/pundit/version.rb#4
Pundit::VERSION = T.let(T.unsafe(nil), String)