Class: Train::Transports::Mock::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- Train::Transports::Mock::Connection
show all
- Defined in:
- lib/train/transports/mock.rb,
lib/train/transports/mock.rb,
lib/train/transports/mock.rb,
lib/train/transports/mock.rb
Defined Under Namespace
Classes: Command, File, OS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(conf = nil) ⇒ Connection
Returns a new instance of Connection.
66
67
68
69
70
71
|
# File 'lib/train/transports/mock.rb', line 66
def initialize(conf = nil)
@conf = conf || {}
@files = {}
@os = OS.new(self, family: 'unknown')
@commands = {}
end
|
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
63
64
65
|
# File 'lib/train/transports/mock.rb', line 63
def commands
@commands
end
|
#files ⇒ Object
Returns the value of attribute files.
63
64
65
|
# File 'lib/train/transports/mock.rb', line 63
def files
@files
end
|
#os ⇒ Object
Returns the value of attribute os.
64
65
66
|
# File 'lib/train/transports/mock.rb', line 64
def os
@os
end
|
Instance Method Details
#command_not_found(cmd) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/train/transports/mock.rb', line 81
def command_not_found(cmd)
if @conf[:verbose]
STDERR.puts('Command not mocked:')
STDERR.puts(' '+cmd.split("\n").join("\n "))
STDERR.puts(' SHA: ' + Digest::SHA256.hexdigest(cmd))
end
mock_command(cmd)
end
|
#file(path) ⇒ Object
101
102
103
|
# File 'lib/train/transports/mock.rb', line 101
def file(path)
@files[path] ||= file_not_found(path)
end
|
#file_not_found(path) ⇒ Object
96
97
98
99
|
# 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) ⇒ Object
77
78
79
|
# 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) ⇒ Object
73
74
75
|
# File 'lib/train/transports/mock.rb', line 73
def mock_os(value)
@os = OS.new(self, value)
end
|
#run_command(cmd) ⇒ Object
90
91
92
93
94
|
# File 'lib/train/transports/mock.rb', line 90
def run_command(cmd)
@commands[cmd] ||
@commands[Digest::SHA256.hexdigest cmd] ||
command_not_found(cmd)
end
|
#to_s ⇒ Object
105
106
107
|
# File 'lib/train/transports/mock.rb', line 105
def to_s
'Mock Connection'
end
|