Method: Rundoc::CodeCommand::FileCommand::Append#call

Defined in:
lib/rundoc/code_command/file_command/append.rb

#call(env = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rundoc/code_command/file_command/append.rb', line 58

def call(env = {})
  mkdir_p
  doc = File.read(filename)
  if @line_number
    puts "Writing to: '#{filename}' line #{@line_number} with: #{contents.inspect}"
    doc = insert_contents_into_at_line(doc)
  else
    puts "Appending to file: '#{filename}' with: #{contents.inspect}"
    doc = concat_with_newline(doc, contents)
  end

  File.write(filename, doc)
  contents
end