INNER CODE UNIT · Ruby
update_readme
hibernate/hibernate-ogm · src/main/release-scripts/pre-release.rb:211
def update_readme(readme_file_name, release_version)
readme = File.read(readme_file_name)
updated_readme = readme.gsub(/^Version:.*$/, "Version: #{release_version} - #{$now.strftime("%d %b %Y")}")
# To write changes to the file, use:
File.open(readme_file_name, "w") {|file| file.puts updated_readme }
end
#######################################################################################################################
def insert_lines(file_name, at_line, new_lines)
open(file_name, 'r+') do |file|
while (at_line -= 1) > 0 # read up to the line you want to write after
file.readline
end
position = file.pos # save your position in the file
rest = file.read # save the rest of the file
file.seek position # go back to the old position
file.puts [new_lines, rest] # write new data & rest of file