Skip to content

Instantly share code, notes, and snippets.

@garyfoster
garyfoster / authority_to_pundit.rake
Last active July 29, 2023 17:28
Quick and Dirty Authority to Pundit Conversion Script
task authority_to_pundit: :environment do
# please note, this script was hastily created and does not convert everything but makes a good start to save some time
# get list of models first because eager loading will crash later after the script modifies code
Rails.application.eager_load!
policies = ApplicationRecord.subclasses.map { |item| { class_name: item.name, policy_name: item.name.underscore } }
# move authorizers to policies
if File.exist?(Rails.root.join('app', 'authorizers'))
FileUtils.mv Rails.root.join('app', 'authorizers'), Rails.root.join('app', 'policies')