Skip to content

Commit ddfba1f

Browse files
committed
Merge pull request #32 from JackDanger/master
Fixed that schema kept prepending additional newlines
2 parents 0076e08 + 1d58ea1 commit ddfba1f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ def annotate_one_file(file_name, info_block, options={})
133133
new_content = old_content.sub(/^# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, info_block)
134134
# But, if there *was* no old schema info, we simply need to insert it
135135
if new_content == old_content
136-
new_content = options[:position] == 'before' ? (info_block + old_content) : (old_content + "\n" + info_block)
136+
new_content = options[:position] == 'before' ?
137+
(info_block + old_content) :
138+
((old_content =~ /\n$/ ? old_content : old_content + '\n') + info_block)
137139
end
138140

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

0 commit comments

Comments
 (0)