module Thor::Actions
def gsub_file(path, flag, *args, &block)
end
match << " no more. Use thor!"
gsub_file 'README', /rake/, :green do |match|
gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
==== Example
config
replacement
flag
path
==== Parameters
Run a regular expression replacement on a file.
def gsub_file(path, flag, *args, &block) return unless behavior == :invoke config = args.last.is_a?(Hash) ? args.pop : {} path = File.expand_path(path, destination_root) say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = File.binread(path) content.gsub!(flag, *args, &block) File.open(path, "wb") { |file| file.write(content) } end end