class Burner::Library::IO::Write

Write value to disk. By default, written files are also logged as WrittenFile instances to the Payload#side_effects array. You can pass in supress_side_effect: true to disable this behavior.

Expected Payload input: anything. Payload output: whatever was passed in.

Attributes

supress_side_effect[R]

Public Class Methods

new( path:, binary: false, disk: {}, name: '', register: DEFAULT_REGISTER, supress_side_effect: false ) click to toggle source
Calls superclass method Burner::Library::IO::OpenFileBase::new
# File lib/burner/library/io/write.rb, line 24
def initialize(
  path:,
  binary: false,
  disk: {},
  name: '',
  register: DEFAULT_REGISTER,
  supress_side_effect: false
)
  @supress_side_effect = supress_side_effect || false

  super(
    binary: binary,
    disk: disk,
    name: name,
    path: path,
    register: register
  )
end

Public Instance Methods

perform(output, payload) click to toggle source
# File lib/burner/library/io/write.rb, line 43
def perform(output, payload)
  logical_filename  = job_string_template(path, output, payload)
  physical_filename = nil

  output.detail("Writing: #{logical_filename}")

  time_in_seconds = Benchmark.measure do
    physical_filename = disk.write(logical_filename, payload[register], binary: binary)
  end.real

  output.detail("Wrote to: #{physical_filename}")

  return if supress_side_effect

  output.detail("Saving to side effects: #{logical_filename}")

  side_effect = SideEffects::WrittenFile.new(
    logical_filename: logical_filename,
    physical_filename: physical_filename,
    time_in_seconds: time_in_seconds
  )

  payload.add_side_effect(side_effect)
end