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


27
28
29
30
31
# File 'lib/winrm/shells/shell_factory.rb', line 27

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

Instance Method Details

#create_shell(shell_type, shell_opts = {}) ⇒ Object

Creates a new shell instance based off the shell_type

Parameters:

  • shell_type (Symbol)

    The shell type :cmd or :powershell

  • shell_opts (Hash) (defaults to: {})

    Options targeted for the created shell

Returns:

  • The ready to use shell instance


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/winrm/shells/shell_factory.rb', line 37

def create_shell(shell_type, shell_opts = {})
  type = shell_type.to_s.capitalize.to_sym
  args = [
    @connection_opts,
    @transport,
    @logger
  ]
  # winrm-elevated has an initializer with no shell_opts so don't break it
  args << shell_opts unless shell_opts.nil? || shell_opts.empty?
  if Shells.constants.include?(type)
    WinRM::Shells.const_get(type).new(*args)
  else
    message = "#{type} is not a valid WinRM shell type. " \
      'Expected either :cmd, :powershell or pluggable shell.'
    raise WinRM::InvalidShellError, message
  end
end