module Thor::Actions
def prepend_file(path, data=nil, config={}, &block)
prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
==== Example
config
data
path
==== Parameters
Prepend text to a file.
def prepend_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = data || block.call content << File.read(path) File.open(path, 'wb') { |file| file.write(content) } end end