INNER CODE UNIT · Ruby
insert_lines
hibernate/hibernate-ogm · src/main/release-scripts/pre-release.rb:220
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
end
end
#######################################################################################################################
def git_commit(file_name, message)
working_dir = File.dirname file_name
git = Git.open(working_dir)
git.add(file_name)
git.commit(message)