@@ -330,8 +330,8 @@ def annotate_one_file(file_name, info_block, position, options={})
330
330
old_columns = old_header && old_header . scan ( column_pattern ) . sort
331
331
new_columns = new_header && new_header . scan ( column_pattern ) . sort
332
332
333
- encoding = Regexp . new ( /(^#\s *encoding:.*\n )|(^# coding:.*\n )|(^# -\* - coding:.*\n )|(^# -\* - encoding\s ?:.*\n )/ )
334
- encoding_header = old_content . match ( encoding ) . to_s
333
+ magic_comment_matcher = Regexp . new ( /(^#\s *encoding:.*\n )|(^# coding:.*\n )|(^# -\* - coding:.*\n )|(^# -\* - encoding\s ?:.*\n )|(^# \s *frozen_string_literal:.+ \n )/ )
334
+ magic_comments = old_content . scan ( magic_comment_matcher ) . flatten . compact
335
335
336
336
if old_columns == new_columns && !options [ :force ]
337
337
return false
@@ -349,12 +349,12 @@ def annotate_one_file(file_name, info_block, position, options={})
349
349
# if there *was* no old schema info (no substitution happened) or :force was passed,
350
350
# we simply need to insert it in correct position
351
351
if new_content == old_content || options [ :force ]
352
- old_content . sub! ( encoding , '' )
352
+ old_content . sub! ( magic_comment_matcher , '' )
353
353
old_content . sub! ( PATTERN , '' )
354
354
355
355
new_content = %w( after bottom ) . include? ( options [ position ] . to_s ) ?
356
- ( encoding_header + ( old_content . rstrip + "\n \n " + wrapped_info_block ) ) :
357
- ( encoding_header + wrapped_info_block + "\n " + old_content )
356
+ ( magic_comments . join + ( old_content . rstrip + "\n \n " + wrapped_info_block ) ) :
357
+ ( magic_comments . join + wrapped_info_block + "\n " + old_content )
358
358
end
359
359
360
360
File . open ( file_name , "wb" ) { |f | f . puts new_content }
0 commit comments