Class: Burner::Library::IO::Exist

Inherits:
Job
  • Object
show all
Defined in:
lib/burner/library/io/exist.rb

Overview

Check to see if a file exists. If short_circuit is set to true and the file does not exist then the job will return false and short circuit the pipeline.

Note: this does not use Payload#registers.

Instance Attribute Summary collapse

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(path:, disk: {}, name: '', short_circuit: false) ⇒ Exist

Returns a new instance of Exist.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
# File 'lib/burner/library/io/exist.rb', line 20

def initialize(path:, disk: {}, name: '', short_circuit: false)
  super(name: name)

  raise ArgumentError, 'path is required' if path.to_s.empty?

  @disk          = Disks.make(disk)
  @path          = path.to_s
  @short_circuit = short_circuit || false
end

Instance Attribute Details

#diskObject (readonly)

Returns the value of attribute disk.



18
19
20
# File 'lib/burner/library/io/exist.rb', line 18

def disk
  @disk
end

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/burner/library/io/exist.rb', line 18

def path
  @path
end

#short_circuitObject (readonly)

Returns the value of attribute short_circuit.



18
19
20
# File 'lib/burner/library/io/exist.rb', line 18

def short_circuit
  @short_circuit
end

Instance Method Details

#perform(output, payload) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/burner/library/io/exist.rb', line 30

def perform(output, payload)
  compiled_path = job_string_template(path, output, payload)

  exists = disk.exist?(compiled_path)
  verb   = exists ? 'does' : 'does not'

  output.detail("The path: #{compiled_path} #{verb} exist")

  # if anything but false is returned then the pipeline will not short circuit.
  payload.halt_pipeline if short_circuit && !exists
end