Sha256: 76aad0c5fee6c939af470e2d0cc8b6433d62a8715c635eded63cc06454be3ef7

Contents?: true

Size: 919 Bytes

Versions: 26

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/simple_cache'

module EacRubyUtils
  module Envs
    class Executable
      include ::EacRubyUtils::SimpleCache

      attr_reader :env, :name, :check_args

      def initialize(env, name, *check_args)
        @env = env
        @name = name
        @check_args = check_args
      end

      def exist?
        exist
      end

      def validate
        return nil if exist?

        "Program \"#{name}\" not found in environment #{env}"
      end

      def validate!
        message = validate

        raise ProgramNotFoundError, message if message
      end

      def command
        validate!
        env.command(name)
      end

      private

      def exist_uncached
        env.command(name, *check_args).execute!
        true
      rescue Errno::ENOENT
        false
      end

      class ProgramNotFoundError < ::StandardError; end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
eac_ruby_utils-0.31.0 lib/eac_ruby_utils/envs/executable.rb
ehbrs-tools-0.7.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.30.0 lib/eac_ruby_utils/envs/executable.rb
ehbrs-tools-0.6.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.29.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.28.0 lib/eac_ruby_utils/envs/executable.rb
ehbrs-tools-0.5.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.27.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.26.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.25.0 lib/eac_ruby_utils/envs/executable.rb
ehbrs-tools-0.3.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.24.1 lib/eac_ruby_utils/envs/executable.rb
ehbrs-tools-0.3.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.24.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.23.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.22.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.21.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.20.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.19.0 lib/eac_ruby_utils/envs/executable.rb
eac_ruby_utils-0.18.1 lib/eac_ruby_utils/envs/executable.rb