Files

File::Mutate

Public Class Methods

mutate_file(file, marker, place, &block) click to toggle source
# File lib/sugar-high/file.rb, line 167
def self.mutate_file file, marker, place, &block
  raise ArgumentError, "You must define a replacement marker for a :before or :after key" if !marker 
         
  replace_in_file file, /(#{marker})/i do |match|
    place == :after ? "#{match}\n  #{yield}" : "#{yield}\n  #{match}"         
  end
end
replace_in_file(path, regexp, *args, &block) click to toggle source
# File lib/sugar-high/file.rb, line 175
def self.replace_in_file(path, regexp, *args, &block)
  content = File.read(path).gsub(regexp, *args, &block)
  File.open(path, 'wb') { |file| file.write(content) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.