Last active
April 4, 2017 13:07
-
-
Save p8/0b308317c45c7d9d10ec01fc59b30fe6 to your computer and use it in GitHub Desktop.
This file contains 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
desc "Copies order insertion" | |
task :copy_order_insertion => :environment do | |
current_version = ENV['CURRENT_VERSION'].try(:upcase) | |
raise "Must specify CURRENT_VERSION" unless current_version | |
new_version = ENV['NEW_VERSION'].try(:upcase) | |
raise "Must specify NEW_VERSION" unless new_version | |
# copy files | |
paths = %w[ | |
app/models | |
app/views | |
spec/models | |
] | |
paths.each do |path| | |
`rm -r #{File.join(path, new_version.underscore )}` | |
`cp -R #{File.join(path, current_version.underscore )} #{File.join(path, new_version.underscore )}` | |
end | |
# replace current_version with new version | |
from = current_version | |
to = new_version | |
roots = paths.map { |path| File.join(path, new_version.underscore ) } | |
roots.each do |dirname| | |
filenames = Dir.glob(File.join(dirname, '**', '*')) | |
filenames.each do |filename| | |
next if File.directory?(filename) | |
##next if exclude_dirs.detect { |exclude_dir| filename[exclude_dir] } | |
body = File.read(filename) | |
new_body = body.gsub(from, to) | |
if body != new_body | |
puts "replace #{from} to #{to} in #{filename}" | |
File.write(filename, new_body) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment