Class: MKBrut::Ops::AppendToFile

Inherits:
BaseOp
  • Object
show all
Defined in:
lib/mkbrut/ops/append_to_file.rb

Instance Method Summary collapse

Methods inherited from BaseOp

dry_run=, dry_run?, #dry_run?, fileutils_args, #fileutils_args

Constructor Details

#initialize(file:, content:) ⇒ AppendToFile

Returns a new instance of AppendToFile.



2
3
4
5
# File 'lib/mkbrut/ops/append_to_file.rb', line 2

def initialize(file:, content:)
  @file    = file
  @content = content
end

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mkbrut/ops/append_to_file.rb', line 7

def call
  if dry_run?
    puts "Would append to #{@file}:\n#{@content}\n"
    return
  end

  contents = File.read(@file)
  File.open(@file, "w") do |file|
    file.puts contents
    file.puts "\n"
    file.puts @content
  end
end