Class: Thor::Actions::InjectIntoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/thor-ssh/actions/inject_into_file.rb

Instance Method Summary collapse

Instance Method Details

#replace!(regexp, string, force) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/thor-ssh/actions/inject_into_file.rb', line 6

def replace!(regexp, string, force)
  unless base.options[:pretend]
    content = base.destination_files.binread(destination)
    if force || !content.include?(replacement)
      content.gsub!(regexp, string)
      base.destination_files.binwrite(destination, content)
    end
  end
end