class FileComposer::Documents::Text

Writes basic, static text file

Attributes

data[R]

Public Class Methods

new(filename:, data: '') click to toggle source
Calls superclass method FileComposer::Documents::Base::new
# File lib/file_composer/documents/text.rb, line 18
def initialize(filename:, data: '')
  super(filename: filename)

  @data = data
end

Public Instance Methods

write!(temp_root = '', store = Stores::Null.new) click to toggle source
# File lib/file_composer/documents/text.rb, line 24
def write!(temp_root = '', store = Stores::Null.new)
  temp_filename = make_temp_filename(temp_root)

  time_in_seconds = Benchmark.measure do
    # First, write out the temporary file
    FileUtils.mkdir_p(File.dirname(temp_filename))
    IO.write(temp_filename, data)
  end.real

  # Then copy the file to permanent store
  physical_filename = store.move!(temp_filename)
  file_result       = FileResult.new(filename, physical_filename)

  Result.new(file_result, time_in_seconds)
end