Skip to content

Commit f1cae61

Browse files
CyborgMasterctran
authored andcommitted
Make sure and use wrappers, even if --force isn't used (#571)
1 parent 37adad4 commit f1cae61

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/annotate/annotate_models.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,16 @@ def annotate_one_file(file_name, info_block, position, options = {})
517517
return false
518518
else
519519
# Replace inline the old schema info with the new schema info
520-
new_content = old_content.sub(annotate_pattern(options), info_block + "\n")
521-
522-
if new_content.end_with?(info_block + "\n")
523-
new_content = old_content.sub(annotate_pattern(options), "\n" + info_block)
524-
end
525-
526520
wrapper_open = options[:wrapper_open] ? "# #{options[:wrapper_open]}\n" : ""
527521
wrapper_close = options[:wrapper_close] ? "# #{options[:wrapper_close]}\n" : ""
528522
wrapped_info_block = "#{wrapper_open}#{info_block}#{wrapper_close}"
523+
524+
new_content = old_content.sub(annotate_pattern(options), wrapped_info_block + "\n")
525+
526+
if new_content.end_with?(wrapped_info_block + "\n")
527+
new_content = old_content.sub(annotate_pattern(options), "\n" + wrapped_info_block)
528+
end
529+
529530
# if there *was* no old schema info (no substitution happened) or :force was passed,
530531
# we simply need to insert it in correct position
531532
if new_content == old_content || options[:force]

0 commit comments

Comments
 (0)