module Rails::Generators::Actions

def append_file_with_newline(path, str, options = {})

Append string to a file with a newline if necessary
def append_file_with_newline(path, str, options = {})
  gsub_file path, /\n?\z/, options do |match|
    match.end_with?("\n") ? "" : "\n#{str}\n"
  end
end