class Pundit::Context

{Pundit::Context} is intended to be created once per request and user, and it is then used to perform authorization checks throughout the request.

@example Using Sinatra

helpers do
  def current_user = ...

  def pundit
    @pundit ||= Pundit::Context.new(user: current_user)
  end
end

get "/posts/:id" do |id|
  pundit.authorize(Post.find(id), query: :show?)
end

@example Using [Roda](roda.jeremyevans.net/index.html)

route do |r|
  context = Pundit::Context.new(user:)

  r.get "posts", Integer do |id|
    context.authorize(Post.find(id), query: :show?)
  end
end