Skip to content

Instantly share code, notes, and snippets.

@J3RN
Last active January 23, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J3RN/54f13ecd07a1b1172df9b9cc158f509e to your computer and use it in GitHub Desktop.
Save J3RN/54f13ecd07a1b1172df9b9cc158f509e to your computer and use it in GitHub Desktop.
Convert proc scopes to stabby lambda scopes
# USAGE: ruby proc_fix.rb <one or more space-separated model names without path or extension>
# e.g. ruby proc_fix.rb activity
# e.g. ruby proc_fix.rb accessory bill_charge
# **Must be run in Rail's root**
# What it do: Converts all "Proc.new { |foo|" to "(foo) -> {"
before = /scope(.*)Proc\.new\s*\{\s*\|(.*)\|/
after = 'scope\1->(\2) {'
ARGV.each do |modelname|
filename = "app/models/#{modelname}.rb"
contents = File.read(filename)
fixed_contents = contents.gsub(before, after)
File.write(filename, fixed_contents)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment