Sha256: 81a061877bc00a292ea5772f75343724f602295a66731b0d493e6e890f92c275
Contents?: true
Size: 1.27 KB
Versions: 41
Compression:
Stored size: 1.27 KB
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 \"#{::Shellwords.join(executable_args)}\" not found in environment #{env}" end def validate! message = validate raise ProgramNotFoundError, message if message end def command(*command_args) validate! env.command(*executable_args, *command_args) end def executable_args executable_args_from_envvar || [name] end def executable_args_envvar "#{name}_command".variableize.upcase end def executable_args_from_envvar ENV[executable_args_envvar].if_present { |v| ::Shellwords.split(v) } end private def exist_uncached env.command(*executable_args, *check_args).execute! true rescue Errno::ENOENT false end class ProgramNotFoundError < ::StandardError; end end end end
Version data entries
41 entries across 41 versions & 3 rubygems