Last active
January 23, 2017 16:22
-
-
Save J3RN/54f13ecd07a1b1172df9b9cc158f509e to your computer and use it in GitHub Desktop.
Convert proc scopes to stabby lambda scopes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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