Method: Pundit.policy

Defined in:
lib/pundit.rb

.policy(user, record) ⇒ Object?

Retrieves the policy for the given record.

Parameters:

  • user (Object)

    the user that initiated the action

  • record (Object)

    the object we're retrieving the policy for

Returns:

  • (Object, nil)

    instance of policy class with query methods

Raises:

See Also:



125
126
127
128
129
130
# File 'lib/pundit.rb', line 125

def policy(user, record)
  policy = PolicyFinder.new(record).policy
  policy.new(user, pundit_model(record)) if policy
rescue ArgumentError
  raise InvalidConstructorError, "Invalid #<#{policy}> constructor is called"
end