Skip to content

Commit 17aba6f

Browse files
committed
allow frozen string literal magic comments
1 parent 695d0dd commit 17aba6f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def annotate_one_file(file_name, info_block, position, options={})
330330
old_columns = old_header && old_header.scan(column_pattern).sort
331331
new_columns = new_header && new_header.scan(column_pattern).sort
332332

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
335335

336336
if old_columns == new_columns && !options[:force]
337337
return false
@@ -349,12 +349,12 @@ def annotate_one_file(file_name, info_block, position, options={})
349349
# if there *was* no old schema info (no substitution happened) or :force was passed,
350350
# we simply need to insert it in correct position
351351
if new_content == old_content || options[:force]
352-
old_content.sub!(encoding, '')
352+
old_content.sub!(magic_comment_matcher, '')
353353
old_content.sub!(PATTERN, '')
354354

355355
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)
358358
end
359359

360360
File.open(file_name, "wb") { |f| f.puts new_content }

0 commit comments

Comments
 (0)