Class: Burner::Library::IO::Write

Inherits:
OpenFileBase show all
Defined in:
lib/burner/library/io/write.rb

Overview

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.

Constant Summary

Constants inherited from JobWithRegister

JobWithRegister::BLANK

Instance Attribute Summary collapse

Attributes inherited from OpenFileBase

#binary, #disk, #path

Attributes inherited from JobWithRegister

#register

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(path:, binary: false, disk: {}, name: '', register: DEFAULT_REGISTER, supress_side_effect: false) ⇒ Write

Returns a new instance of Write.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

Instance Attribute Details

#supress_side_effectObject (readonly)

Returns the value of attribute supress_side_effect.



22
23
24
# File 'lib/burner/library/io/write.rb', line 22

def supress_side_effect
  @supress_side_effect
end

Instance Method Details

#perform(output, payload) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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