Class Pundit::PolicyFinder
In: lib/pundit/policy_finder.rb
Parent: Object

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

Methods

new   param_key   policy   policy!   scope   scope!  

Attributes

object  [R] 

Public Class methods

@param object [any] the object to find policy and scope classes for

Public Instance methods

@return [String] the name of the key this object would have in a params hash

@return [nil, Class] policy class with query methods @see github.com/varvet/pundit#policies @example

  policy = finder.policy #=> UserPolicy
  policy.show? #=> true
  policy.update? #=> false

@return [Class] policy class with query methods @raise [NotDefinedError] if policy could not be determined

@return [nil, Scope{resolve}] scope class which can resolve to a scope @see github.com/varvet/pundit#scopes @example

  scope = finder.scope #=> UserPolicy::Scope
  scope.resolve #=> <#ActiveRecord::Relation ...>

@return [Scope{resolve}] scope class which can resolve to a scope @raise [NotDefinedError] if scope could not be determined

[Validate]