class Train::Transports::Mock::Connection

Constants

Command

Attributes

commands[RW]
files[RW]
os[R]

Public Class Methods

new(conf = nil) click to toggle source
# File lib/train/transports/mock.rb, line 66
def initialize(conf = nil)
  @conf = conf || {}
  @files = {}
  @os = OS.new(self, family: 'unknown')
  @commands = {}
end

Public Instance Methods

command_not_found(cmd) click to toggle source
# File lib/train/transports/mock.rb, line 81
def command_not_found(cmd)
  if @conf[:verbose]
    STDERR.puts('Command not mocked:')
    STDERR.puts('    '+cmd.to_s.split("\n").join("\n    "))
    STDERR.puts('    SHA: ' + Digest::SHA256.hexdigest(cmd.to_s))
  end
  mock_command(cmd)
end
file(path) click to toggle source
# File lib/train/transports/mock.rb, line 101
def file(path)
  @files[path] ||= file_not_found(path)
end
file_not_found(path) click to toggle source
# File lib/train/transports/mock.rb, line 96
def file_not_found(path)
  STDERR.puts('File not mocked: '+path.to_s) if @conf[:verbose]
  File.new(self, path)
end
mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0) click to toggle source
# File lib/train/transports/mock.rb, line 77
def mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0)
  @commands[cmd] = Command.new(stdout || '', stderr || '', exit_status)
end
mock_os(value) click to toggle source
# File lib/train/transports/mock.rb, line 73
def mock_os(value)
  @os = OS.new(self, value)
end
run_command(cmd) click to toggle source
# File lib/train/transports/mock.rb, line 90
def run_command(cmd)
  @commands[cmd] ||
    @commands[Digest::SHA256.hexdigest cmd.to_s] ||
    command_not_found(cmd)
end
to_s() click to toggle source
# File lib/train/transports/mock.rb, line 105
def to_s
  'Mock Connection'
end