class WinRM::Transport::ShellCloser

An object that can close a remote shell session over WinRM.

@author Fletcher Nichol <fnichol@nichol.ca>

Attributes

shell_id[RW]

@return [String,nil] the identifier for the current open remote

shell session

Public Class Methods

new(info, debug, args) click to toggle source

Constructs a new ShellCloser.

@param info [String] a string representation of the connection @param debug [true,false] whether or not debug messages should be

output

@param args [Array] arguments to construct a `WinRM::WinRMWebService`

# File lib/winrm/transport/shell_closer.rb, line 37
def initialize(info, debug, args)
  @info = info
  @debug = debug
  @args = args
end

Public Instance Methods

call(*) click to toggle source

Closes the remote shell session.

# File lib/winrm/transport/shell_closer.rb, line 44
def call(*)
  debug("[CommandExecutor] closing remote shell #{@shell_id} on #{@info}")
  ::WinRM::WinRMWebService.new(*@args).close_shell(@shell_id)
  debug("[CommandExecutor] remote shell #{@shell_id} closed")
rescue => e
  debug("Exception: #{e.inspect}")
end
for(shell_id) click to toggle source

@param shell_id [String] a remote shell ID @return [ShellCloser] a new ShellCloser with a copy of this object's

state and the shell_id set to the given parameter value
# File lib/winrm/transport/shell_closer.rb, line 55
def for(shell_id)
  self.class.new(@info, @debug, @args).tap { |c| c.shell_id = shell_id }
end

Private Instance Methods

debug(message) click to toggle source

Writes a debug message, if debug mode is enabled.

@param message [String] a message @api private

# File lib/winrm/transport/shell_closer.rb, line 65
def debug(message)
  $stdout.puts "D      #{message}" if @debug
end