Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- namespace :encoding do
- task :update_files do
- Dir.glob("{app,config,spec,test,lib,db,features}/**/*.{rb,rake}").each do |f|
- add_encoding(f)
- end
- end
- def add_encoding(file_name, encoding = 'utf-8')
- if File.exist?(file_name)
- old_content = File.read(file_name)
- # Ignore the Schema version line because it changes with each migration
- encoding_regexp = Regexp.new(/^# encoding: (.*)$/)
- match_data = old_content.match(encoding_regexp)
- old_encoding = match_data ? match_data.captures[0].strip : ""
- puts "#{file_name}: #{old_encoding}"
- unless old_encoding == encoding
- puts " => Changing encoding '#{old_encoding}' to '#{encoding}'"
- old_content.sub!(encoding_regexp, '')
- new_content = "# encoding: #{encoding} \n#{old_content}"
- File.open(file_name, "wb") { |f| f.puts new_content }
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment