class Prerequisites
Attributes
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/prerequisites.rb, line 6 def initialize(config) @config = config end
Public Instance Methods
check()
click to toggle source
# File lib/prerequisites.rb, line 10 def check environment_variables executables_in_path shell_commands end
Private Instance Methods
check_env_var_has_value(var, value)
click to toggle source
# File lib/prerequisites.rb, line 61 def check_env_var_has_value(var, value) unless ENV[var] == value raise Prerequisites::EnvironmentVariableError.new( "Expected environment variable #{var} to be #{value}" ) end end
check_env_var_is_set(env_var)
click to toggle source
# File lib/prerequisites.rb, line 53 def check_env_var_is_set(env_var) unless ENV.key?(env_var) raise Prerequisites::EnvironmentVariableError.new( "Required environment variable #{env_var} is not set" ) end end
check_executable(executable)
click to toggle source
# File lib/prerequisites.rb, line 69 def check_executable(executable) _, _, status = Open3.capture3("which #{executable}") unless status.success? raise Prerequisites::ExecutableError.new( "Required executable #{executable} not found in path" ) end end
environment_variables()
click to toggle source
# File lib/prerequisites.rb, line 18 def environment_variables config.dig(:environment_variables).to_a.each do |env_var| if env_var.is_a?(Hash) var, value = env_var.first check_env_var_has_value(var, value) else check_env_var_is_set(env_var) end end true end
executables_in_path()
click to toggle source
# File lib/prerequisites.rb, line 31 def executables_in_path config.dig(:executables_in_path).to_a.each do |executable| check_executable(executable) end true end
shell_commands()
click to toggle source
# File lib/prerequisites.rb, line 39 def shell_commands config.dig(:shell_commands).to_a.each do |cmd| _, _, status = Open3.capture3(cmd) unless status.success? raise Prerequisites::ShellCommandError.new( "Shell command check failed: #{cmd}" ) end end true end