Class: WinRM::Shells::ShellFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm/shells/shell_factory.rb

Overview

Factory for creating concrete shell instances

Instance Method Summary collapse

Constructor Details

#initialize(connection_opts, transport, logger) ⇒ ShellFactory

Creates a new ShellFactory instance

Parameters:

  • connection_opts (ConnectionOpts)

    The WinRM connection options

  • transport (HttpTransport)

    The WinRM SOAP transport for sending messages

  • logger (Logger)

    The logger to log messages to



29
30
31
32
33
# File 'lib/winrm/shells/shell_factory.rb', line 29

def initialize(connection_opts, transport, logger)
  @connection_opts = connection_opts
  @transport = transport
  @logger = logger
end

Instance Method Details

#create_shell(shell_type) ⇒ Object

Creates a new shell instance based off the shell_type

Parameters:

  • shell_type (Symbol)

    The shell type :cmd or :powershell

Returns:

  • The ready to use shell instance



38
39
40
41
42
43
44
45
46
47
# File 'lib/winrm/shells/shell_factory.rb', line 38

def create_shell(shell_type)
  type = shell_type.to_s.capitalize.to_sym
  if Shells.constants.include?(type)
    WinRM::Shells.const_get(type).new(@connection_opts, @transport, @logger)
  else
    message = "#{type} is not a valid WinRM shell type. " \
      'Expected either :cmd, :powershell or pluggable shell.'
    raise WinRM::InvalidShellError, message
  end
end