Skip to content

Commit 1d58ea1

Browse files
committed
not continually prepending newlines.
Prior to this patch every time the schema was regenerated at the end of the file it prepended an additional newline character. This made the schema slowly creep down the file over time. Finally annoyed me enough to fork and fix ;)
1 parent 0076e08 commit 1d58ea1

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)