Method: Rye::Cmd#file_append

Defined in:
lib/rye/cmd.rb

#file_append(filepath, newcontent, backup = false) ⇒ Object

Append newcontent to remote filepath. If the file doesn’t exist it will be created. If backup is specified, filepath will be copied to filepath-previous before appending.

NOTE: Not recommended for large files. It downloads the contents.



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rye/cmd.rb', line 204

def file_append(filepath, newcontent, backup=false)
  content = StringIO.new
  
  if self.file_exists?(filepath)
    self.cp filepath, "#{filepath}-previous" if backup
    content = self.file_download filepath
  end
  
  if newcontent.is_a?(StringIO)
    newcontent.rewind
    content.puts newcontent.read
  else
    content.puts newcontent
  end
  
  self.file_upload content, filepath
end