Sha256: 510c4cb640b6da8830e334cd6923efde6a409b08a7818807de558a7b3e857a1f

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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.
#

require_relative 'base'

module Burner
  class Jobs
    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.
      class Exist < Base
        attr_reader :short_circuit

        def initialize(name:, path:, short_circuit: false)
          super(name: name, path: path)

          @short_circuit = short_circuit || false

          freeze
        end

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

          exists = File.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.  So
          # we need to make sure we explicitly return false.
          short_circuit && !exists ? false : nil
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
burner-1.0.0.pre.alpha.5 lib/burner/jobs/io/exist.rb
burner-1.0.0.pre.alpha.4 lib/burner/jobs/io/exist.rb