train-core 2.0.2 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db2ad45d3072254fd74ceee17d42a00703367b7cde8734f3f77ec6f7790f3d4
4
- data.tar.gz: c4e41ccc184b55ed2fa476bb291b29b044f1a216f0afe033921103efed9babe5
3
+ metadata.gz: 84c1a550a64252e1bc30666a40359220d3afdc76403ee8bd580c4fb49cd54c49
4
+ data.tar.gz: 545681f44366939e9fa22e92b5bd8397fae14b0e5407ab92cdfc456679d5dd66
5
5
  SHA512:
6
- metadata.gz: b74e6de494689d8643b942f473c6f6b7b62d0c6ff0e384af968f25a6841f9536ede13adfb82eaf0d2a88025def4e37e9c419a63873880dd07c5bce6775efdc73
7
- data.tar.gz: 2dd12c74d52951acd2b860e6f879731f8fbc6a1f8fb9ba363d69b838a9d588d0f90bfc55781766525d45c1c0d2318bdfd2f3c82a9f8d14891a19cbb86058ab0c
6
+ metadata.gz: 25c0429f61b1b911e4d32952e53815f689ea9e76eee8fc1d1a1bb8f04f1be82b6f442d9ee11cb1ac91cd162c98606ad9961290fc177625af32dd6ab72a90e258
7
+ data.tar.gz: 0d1e3a0368830194f669f6623b253679d847a0018137c8a37610d1648d94d91e28497d8e34bd4f50a20515662f8dee890b70908121e81acf96b98b1788e2ccbd
@@ -14,8 +14,7 @@ module Train::Platforms::Detect::Helpers
14
14
  end
15
15
 
16
16
  def winrm?
17
- Object.const_defined?('Train::Transports::WinRM::Connection') &&
18
- @backend.class == Train::Transports::WinRM::Connection
17
+ @backend.class.to_s == 'Train::Transports::WinRM::Connection'
19
18
  end
20
19
 
21
20
  def unix_file_contents(path)
@@ -37,6 +37,7 @@ module Train::Platforms::Detect::Helpers
37
37
 
38
38
  raw.lines.each_with_object({}) do |line, memo|
39
39
  line.strip!
40
+ next if line.start_with?('#')
40
41
  next if line.empty?
41
42
  key, value = line.split('=', 2)
42
43
  memo[key] = value.gsub(/\A"|"\Z/, '') unless value.empty?
@@ -114,10 +114,14 @@ class Train::Plugins::Transport
114
114
 
115
115
  # This is the main command call for all connections. This will call the private
116
116
  # run_command_via_connection on the connection with optional caching
117
- def run_command(cmd)
118
- return run_command_via_connection(cmd) unless cache_enabled?(:command)
117
+ #
118
+ # This command accepts an optional data handler block. When provided,
119
+ # inbound data will be published vi `data_handler.call(data)`. This can allow
120
+ # callers to receive and render updates from remote command execution.
121
+ def run_command(cmd, &data_handler)
122
+ return run_command_via_connection(cmd, &data_handler) unless cache_enabled?(:command)
119
123
 
120
- @cache[:command][cmd] ||= run_command_via_connection(cmd)
124
+ @cache[:command][cmd] ||= run_command_via_connection(cmd, &data_handler)
121
125
  end
122
126
 
123
127
  # This is the main file call for all connections. This will call the private
@@ -150,8 +154,13 @@ class Train::Plugins::Transport
150
154
  # Execute a command using this connection.
151
155
  #
152
156
  # @param command [String] command string to execute
157
+ # @param &data_handler(data) [Proc] proc that is called when data arrives from
158
+ # the connection. This block is optional. Individual transports will need
159
+ # to explicitly invoke the block in their implementation of run_command_via_connection;
160
+ # if they do not, the block is ignored and will not be used to report data back to the caller.
161
+ #
153
162
  # @return [CommandResult] contains the result of running the command
154
- def run_command_via_connection(_command)
163
+ def run_command_via_connection(_command, &_data_handler)
155
164
  fail NotImplementedError, "#{self.class} does not implement #run_command_via_connection()"
156
165
  end
157
166
 
@@ -71,7 +71,7 @@ module Train::Transports
71
71
  end
72
72
  end
73
73
 
74
- def run_command_via_connection(cmd)
74
+ def run_command_via_connection(cmd, &_data_handler)
75
75
  # Use the runner if it is available
76
76
  return @runner.run_command(cmd) if defined?(@runner)
77
77
 
@@ -124,7 +124,7 @@ class Train::Transports::Mock
124
124
 
125
125
  private
126
126
 
127
- def run_command_via_connection(cmd)
127
+ def run_command_via_connection(cmd, &_data_handler)
128
128
  @cache[:command][Digest::SHA256.hexdigest cmd.to_s] ||
129
129
  command_not_found(cmd)
130
130
  end
data/lib/train/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '2.0.2'.freeze
6
+ VERSION = '2.0.5'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-19 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.1
116
+ rubygems_version: 3.0.3
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Transport interface to talk to a selected set of backends.