Method: Ing::Files#prepend_to_file

Defined in:
lib/ing/actions/file_manipulation.rb

#prepend_to_file(path, *args, &block) ⇒ Object Also known as: prepend_file

Prepend text to a file. Since it depends on insert_into_file, it’s reversible.

Parameters

path<String>

path of the file to be changed

data<String>

the data to prepend to the file, can be also given as a block.

config<Hash>

give :verbose => false to not log the status.

Example

prepend_to_file 'config/environments/test.rb', 'config.gem "rspec"'

prepend_to_file 'config/environments/test.rb' do
  'config.gem "rspec"'
end


150
151
152
153
154
# File 'lib/ing/actions/file_manipulation.rb', line 150

def prepend_to_file(path, *args, &block)
  config = args.last.is_a?(Hash) ? args.pop : {}
  config.merge!(:after => /\A/)
  insert_into_file(path, *(args << config), &block)
end