Commit f62749b6 by Yuanxuan Wang

Leave magic encoding comment intact

parent cfeec96c
...@@ -131,6 +131,9 @@ module AnnotateModels ...@@ -131,6 +131,9 @@ module AnnotateModels
old_columns = old_header && old_header.scan(column_pattern).sort old_columns = old_header && old_header.scan(column_pattern).sort
new_columns = new_header && new_header.scan(column_pattern).sort new_columns = new_header && new_header.scan(column_pattern).sort
encoding = Regexp.new(/(^# encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)/)
encoding_header = old_content.match(encoding).to_s
if old_columns == new_columns if old_columns == new_columns
false false
else else
...@@ -138,9 +141,10 @@ module AnnotateModels ...@@ -138,9 +141,10 @@ module AnnotateModels
new_content = old_content.sub(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, info_block) new_content = old_content.sub(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, info_block)
# But, if there *was* no old schema info, we simply need to insert it # But, if there *was* no old schema info, we simply need to insert it
if new_content == old_content if new_content == old_content
old_content.sub!(encoding, '')
new_content = options[:position] == 'before' ? new_content = options[:position] == 'before' ?
(info_block + old_content) : (encoding_header + info_block + old_content) :
((old_content =~ /\n$/ ? old_content : old_content + '\n') + info_block) (encoding_header + (old_content =~ /\n$/ ? old_content : old_content + '\n') + info_block)
end end
File.open(file_name, "wb") { |f| f.puts new_content } File.open(file_name, "wb") { |f| f.puts new_content }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment