Class: Train::Transports::Mock::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- Train::Transports::Mock::Connection
- Defined in:
- lib/train/transports/mock.rb,
lib/train/transports/mock.rb,
lib/train/transports/mock.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #command_not_found(cmd) ⇒ Object
- #commands ⇒ Object
- #commands=(commands) ⇒ Object
- #file_not_found(path) ⇒ Object
- #files ⇒ Object
- #files=(files) ⇒ Object
-
#initialize(conf = nil) ⇒ Connection
constructor
A new instance of Connection.
- #mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0) ⇒ Object
- #mock_os(value = {}) ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(conf = nil) ⇒ Connection
Returns a new instance of Connection.
62 63 64 65 66 67 |
# File 'lib/train/transports/mock.rb', line 62 def initialize(conf = nil) super(conf) mock_os enable_cache(:file) enable_cache(:command) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
60 61 62 |
# File 'lib/train/transports/mock.rb', line 60 def @options end |
Instance Method Details
#command_not_found(cmd) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/train/transports/mock.rb', line 106 def command_not_found(cmd) if @options[: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 # return a non-zero exit code mock_command(cmd, nil, nil, 1) end |
#commands ⇒ Object
90 91 92 |
# File 'lib/train/transports/mock.rb', line 90 def commands @cache[:command] end |
#commands=(commands) ⇒ Object
86 87 88 |
# File 'lib/train/transports/mock.rb', line 86 def commands=(commands) @cache[:command] = commands end |
#file_not_found(path) ⇒ Object
116 117 118 119 |
# File 'lib/train/transports/mock.rb', line 116 def file_not_found(path) STDERR.puts('File not mocked: '+path.to_s) if @options[:verbose] File.new(self, path) end |
#files ⇒ Object
98 99 100 |
# File 'lib/train/transports/mock.rb', line 98 def files @cache[:file] end |
#files=(files) ⇒ Object
94 95 96 |
# File 'lib/train/transports/mock.rb', line 94 def files=(files) @cache[:file] = files end |
#mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0) ⇒ Object
102 103 104 |
# File 'lib/train/transports/mock.rb', line 102 def mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0) @cache[:command][cmd] = Command.new(stdout || '', stderr || '', exit_status) end |
#mock_os(value = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/train/transports/mock.rb', line 73 def mock_os(value = {}) # if a user passes a nil value, set to an empty hash so the merge still succeeds value ||= {} value.each { |k, v| value[k] = 'unknown' if v.nil? } value = { name: 'mock', family: 'mock', release: 'unknown', arch: 'unknown' }.merge(value) platform = Train::Platforms.name(value[:name]) platform.family_hierarchy = family_hierarchy(platform).flatten platform.platform = value platform.add_platform_methods @platform = platform end |
#to_s ⇒ Object
121 122 123 |
# File 'lib/train/transports/mock.rb', line 121 def to_s 'Mock Connection' end |
#uri ⇒ Object
69 70 71 |
# File 'lib/train/transports/mock.rb', line 69 def uri 'mock://' end |