Skip to content

Commit

Permalink
Merge pull request #165 from swistak/develop
Browse files Browse the repository at this point in the history
Replacing old block with new one.
  • Loading branch information
ctran committed Feb 24, 2014
2 parents 7cbdba6 + b11928e commit 54a99db
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,17 @@ def annotate_one_file(file_name, info_block, position, options={})
# end
# =======

# Strip the old schema info, and insert new schema info.
old_content.sub!(encoding, '')
old_content.sub!(PATTERN, '')

new_content = options[position].to_s == 'after' ?
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
(encoding_header + info_block + "\n" + old_content)
if PATTERN.match(old_content)
new_content = old_content.sub(PATTERN, info_block)
else
# Strip the old schema info, and insert new schema info.
old_content.sub!(encoding, '')
old_content.sub!(PATTERN, '')

new_content = options[position].to_s == 'after' ?
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
(encoding_header + info_block + "\n" + old_content)
end

File.open(file_name, "wb") { |f| f.puts new_content }
return true
Expand Down

0 comments on commit 54a99db

Please sign in to comment.