Sha256: 2a96dcb80101270136ef323d725cbca1a7ab1cc4ef095435cc5c41cd1485870a

Contents?: true

Size: 912 Bytes

Versions: 14

Compression:

Stored size: 912 Bytes

Contents

module WatchmonkeyCli
  module Checkers
    class FileExists < Checker
      self.checker_name = "unix_file_exists"

      def enqueue host, file, opts = {}
        opts = { message: "File #{file} does not exist!" }.merge(opts)
        host = app.fetch_connection(:loopback, :local) if !host || host == :local
        host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
        app.enqueue(self, host, file, opts)
      end

      def check! result, host, file, opts = {}
        if host.is_a?(WatchmonkeyCli::LoopbackConnection)
          result.error! "#{opts[:message]} (ENOENT)" if !File.exist?(file)
        else
          result.command = "test -f #{Shellwords.escape(file)} && echo exists"
          result.result = host.exec(result.command)
          result.error! "#{opts[:message]} (#{result.result.presence || "ENOENT"})" if result.result != "exists"
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
watchmonkey_cli-1.12.0 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.11.0 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.10.0 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.9.1 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.9.0 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.6 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.5 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.4 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.3 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.2 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8.1 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.8 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.7.1 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.7 lib/watchmonkey_cli/checkers/unix_file_exists.rb