Sha256: cba125ffb37dbb32642f9a6016ccc6e6479a4b6fa77a87718e012599667eafa4

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Burner
  module Library
    module IO
      # 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.
      class Exist < Job
        attr_reader :disk, :path, :short_circuit

        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

        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
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
burner-1.12.0 lib/burner/library/io/exist.rb
burner-1.11.0 lib/burner/library/io/exist.rb
burner-1.10.0 lib/burner/library/io/exist.rb
burner-1.9.0 lib/burner/library/io/exist.rb
burner-1.9.0.pre.alpha lib/burner/library/io/exist.rb
burner-1.8.0 lib/burner/library/io/exist.rb
burner-1.7.0 lib/burner/library/io/exist.rb
burner-1.7.0.pre.alpha lib/burner/library/io/exist.rb