Skip to content

Instantly share code, notes, and snippets.

@blackxored
Last active August 29, 2015 14:04
Show Gist options
  • Save blackxored/7460c13f1a211e1c9164 to your computer and use it in GitHub Desktop.
Save blackxored/7460c13f1a211e1c9164 to your computer and use it in GitHub Desktop.
module PunditExtensions
def authorize(record, query=nil, account_or_job=nil)
preload_permissions(record)
deal_with_account_or_job(record, account_or_job) if account_or_job
super
end
def preload_permissions(record)
@preloaded ||= {}
@preloaded[:permissions] ||= {}
@preloaded[:permissions].merge!(policy(record).to_permissions_hash)
end
def deal_with_account_or_job(record, account_or_job)
# ...
end
end
Pundit.send(:prepend, PunditExtensions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment