Class: CemWinSpec::WinExec::BaseCmd

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_win_spec/win_exec/cmd/base_cmd.rb

Direct Known Subclasses

LocalCmd, WinRMCmd

Constant Summary collapse

COMMAND_SEPARATOR =
'; '
PUPPET_VER_TO_RUBY_VER =
{
  '7' => '278',
  '8' => '322',
}.freeze
TOOL_DIR_BY_RUBY_VER =
{
  '278' => 'C:/tools/ruby/2.7.8',
  '322' => 'C:/tools/ruby/3.2.2',
}.freeze

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#current_log_format, current_log_format, current_log_level, #current_log_level, included, log_setup!, #log_setup!, logger, #logger, new_log_formatter, #new_log_formatter, new_log_level, #new_log_level

Constructor Details

#initialize(working_dir = nil, puppet_version: nil, **env_vars) ⇒ BaseCmd

Returns a new instance of BaseCmd.



22
23
24
25
26
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 22

def initialize(working_dir = nil, puppet_version: nil, **env_vars)
  @working_dir = working_dir
  self.puppet_version = puppet_version
  self.env_vars = env_vars
end

Instance Attribute Details

#env_varsObject

Returns the value of attribute env_vars.



20
21
22
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 20

def env_vars
  @env_vars
end

#puppet_versionObject

Returns the value of attribute puppet_version.



20
21
22
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 20

def puppet_version
  @puppet_version
end

#working_dirObject

Returns the value of attribute working_dir.



20
21
22
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 20

def working_dir
  @working_dir
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 55

def available?
  raise NotImplementedError
end

#command(cmd) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 72

def command(cmd)
  cmd = [cmd]
  cmd.unshift(change_ruby_version_cmd) if ruby_version # executes third
  env_vars.each { |k, v| cmd.unshift(set_env_var_cmd(k, v)) } if env_vars.any? # executes second
  cmd.unshift(change_working_dir_cmd(working_dir)) if working_dir # executes first
  cmd.join(COMMAND_SEPARATOR)
end

#ruby_versionString?

Returns the ruby version that will be used to execute the command The ruby version is determined by the puppet version that is set

Returns:

  • (String, nil)

    the ruby version or nil if the puppet version is not set



66
67
68
69
70
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 66

def ruby_version
  return nil unless puppet_version

  PUPPET_VER_TO_RUBY_VER[puppet_version.split('.')[0]]
end

#run(cmd, *_args, **_kwargs) ⇒ Object

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 59

def run(cmd, *_args, **_kwargs)
  raise NotImplementedError
end