Class: RemoteExec::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/remote-exec/local.rb

Overview

Class to run local commands and transfer files localy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#shutdown

Constructor Details

#initialize(shell = "sh") {|self| ... } ⇒ Local

Constructs a new Local object.

Parameters:

  • shell (String) (defaults to: "sh")

    name of the shell to run

Yields:

  • (self)

    if a block is given then the constructed object yields itself and calls #shutdown at the end, closing the remote connection



22
23
24
25
# File 'lib/remote-exec/local.rb', line 22

def initialize(shell = "sh")
  @shell = shell
  super()
end

Instance Attribute Details

#shellObject (readonly)

name of the shell to run



13
14
15
# File 'lib/remote-exec/local.rb', line 13

def shell
  @shell
end

Instance Method Details

#execute(command) ⇒ Integer

Execute command locally

Parameters:

  • command (String)

    command string to execute

Returns:

  • (Integer)

    exit status of the command



33
34
35
36
37
38
39
40
41
42
# File 'lib/remote-exec/local.rb', line 33

def execute(command)
  before_execute.changed_and_notify(self, command)
  shell_session.execute(command) do |out,err|
    on_execute_data.changed_and_notify(self, out, err)
    yield(out, err) if block_given?
  end
  last_status = shell_session.status
  after_execute.changed_and_notify(self, command, last_status)
  last_status
end