Class: Burner::Library::IO::Exist
- 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
-
#disk ⇒ Object
readonly
Returns the value of attribute disk.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#short_circuit ⇒ Object
readonly
Returns the value of attribute short_circuit.
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(path:, disk: {}, name: '', short_circuit: false) ⇒ Exist
constructor
A new instance of Exist.
- #perform(output, payload) ⇒ Object
Methods included from Util::Arrayable
Constructor Details
#initialize(path:, disk: {}, name: '', short_circuit: false) ⇒ Exist
Returns a new instance of Exist.
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
#disk ⇒ Object (readonly)
Returns the value of attribute disk.
18 19 20 |
# File 'lib/burner/library/io/exist.rb', line 18 def disk @disk end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/burner/library/io/exist.rb', line 18 def path @path end |
#short_circuit ⇒ Object (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 |