Class: CemWinSpec::WinExec::BaseCmd
- Inherits:
-
Object
- Object
- CemWinSpec::WinExec::BaseCmd
- Includes:
- Logging
- Defined in:
- lib/cem_win_spec/win_exec/cmd/base_cmd.rb
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
Instance Attribute Summary collapse
-
#env_vars ⇒ Object
Returns the value of attribute env_vars.
-
#puppet_version ⇒ Object
Returns the value of attribute puppet_version.
-
#working_dir ⇒ Object
Returns the value of attribute working_dir.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #command(cmd) ⇒ Object
-
#initialize(working_dir = nil, puppet_version: nil, **env_vars) ⇒ BaseCmd
constructor
A new instance of BaseCmd.
-
#ruby_version ⇒ String?
Returns the ruby version that will be used to execute the command The ruby version is determined by the puppet version that is set.
- #run(cmd, *_args, **_kwargs) ⇒ Object
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_vars ⇒ Object
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_version ⇒ Object
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_dir ⇒ Object
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
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_version ⇒ String?
Returns the ruby version that will be used to execute the command The ruby version is determined by the puppet version that is 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
59 60 61 |
# File 'lib/cem_win_spec/win_exec/cmd/base_cmd.rb', line 59 def run(cmd, *_args, **_kwargs) raise NotImplementedError end |