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
-
#os ⇒ Object
readonly
Returns the value of attribute os.
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
- #mock_os_hierarchy(plat) ⇒ 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
#os ⇒ Object (readonly)
Returns the value of attribute os.
60 61 62 |
# File 'lib/train/transports/mock.rb', line 60 def os @os end |
Instance Method Details
#command_not_found(cmd) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/train/transports/mock.rb', line 113 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
97 98 99 |
# File 'lib/train/transports/mock.rb', line 97 def commands @cache[:command] end |
#commands=(commands) ⇒ Object
93 94 95 |
# File 'lib/train/transports/mock.rb', line 93 def commands=(commands) @cache[:command] = commands end |
#file_not_found(path) ⇒ Object
123 124 125 126 |
# File 'lib/train/transports/mock.rb', line 123 def file_not_found(path) STDERR.puts('File not mocked: '+path.to_s) if @options[:verbose] File.new(self, path) end |
#files ⇒ Object
105 106 107 |
# File 'lib/train/transports/mock.rb', line 105 def files @cache[:file] end |
#files=(files) ⇒ Object
101 102 103 |
# File 'lib/train/transports/mock.rb', line 101 def files=(files) @cache[:file] = files end |
#mock_command(cmd, stdout = nil, stderr = nil, exit_status = 0) ⇒ Object
109 110 111 |
# File 'lib/train/transports/mock.rb', line 109 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 = mock_os_hierarchy(platform).flatten platform.platform = value platform.add_platform_methods @os = platform end |
#mock_os_hierarchy(plat) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/train/transports/mock.rb', line 86 def mock_os_hierarchy(plat) plat.families.each_with_object([]) do |(k, _v), memo| memo << k.name memo << mock_os_hierarchy(k) unless k.families.empty? end end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/train/transports/mock.rb', line 128 def to_s 'Mock Connection' end |
#uri ⇒ Object
69 70 71 |
# File 'lib/train/transports/mock.rb', line 69 def uri 'mock://' end |