Class: RemoteExec::Fake

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

Overview

Class to fake running commands and transfering files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#shutdown

Constructor Details

#initialize {|self| ... } ⇒ Fake

Constructs a new Fake object.

Yields:

  • (self)

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



29
30
31
32
# File 'lib/remote-exec/fake.rb', line 29

def initialize
  after_connect.changed_and_notify(self)
  super
end

Instance Attribute Details

#storyArray

The story to tell in execute, take an array

Examples:

usage


[1, [[nil,"error\n"]]

Returns:

  • (Array)

    story to run in execute, format: [ return_status, [[ stdout, stderr],…] ]



21
22
23
# File 'lib/remote-exec/fake.rb', line 21

def story
  @story
end

Instance Method Details

#execute(command) ⇒ Integer

Execute fake command

Parameters:

  • command (String)

    command string to execute

Returns:

  • (Integer)

    exit status of the command



40
41
42
43
44
45
46
47
48
49
# File 'lib/remote-exec/fake.rb', line 40

def execute(command)
  before_execute.changed_and_notify(self, command)
  last_status, outputs = @story
  outputs.each do |out, err|
    on_execute_data.changed_and_notify(self, out, err)
    yield(out, err) if block_given?
  end
  after_execute.changed_and_notify(self, command, last_status)
  last_status
end