Module: PrependFile

Defined in:
lib/prependfile.rb,
lib/prependfile/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.prepend(old_file, data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prependfile.rb', line 6

def prepend(old_file, data)
  temp_file = Tempfile.open('prependfile')
  begin
    #prepend data
    write_to_temp(temp_file, data)
    #write old file to temp
    write_to_temp(temp_file, old_file)
    #move temp file to original location
    move_temp_to_original(temp_file, old_file)
  ensure
    temp_file.close
    temp_file.unlink
  end
end