Class: CemWinSpec::WinExec::Output
- Inherits:
-
Object
- Object
- CemWinSpec::WinExec::Output
show all
- Includes:
- Logging
- Defined in:
- lib/cem_win_spec/win_exec/output.rb
Overview
Wrapper class for WinRM::Output
Constant Summary
Constants included
from Logging
Logging::LEVEL_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
#current_log_format, current_log_format, current_log_level, #current_log_level, included, log_setup!, #log_setup!, logger, #logger, new_log_formatter, #new_log_formatter, new_log_level, #new_log_level
Constructor Details
#initialize(output, quiet: false, line_prefix: " #$ ") ⇒ Output
Returns a new instance of Output.
14
15
16
17
18
19
20
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 14
def initialize(output, quiet: false, line_prefix: " #$ ")
@raw_output = output
@quiet = quiet
@line_prefix = line_prefix
@pending_threaded = nil
set_vars_from_output(output)
end
|
Instance Attribute Details
#exitcode ⇒ Object
Returns the value of attribute exitcode.
12
13
14
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 12
def exitcode
@exitcode
end
|
#stderr ⇒ Object
Returns the value of attribute stderr.
12
13
14
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 12
def stderr
@stderr
end
|
#stdout ⇒ Object
Returns the value of attribute stdout.
12
13
14
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 12
def stdout
@stdout
end
|
Instance Method Details
#inspect ⇒ Object
66
67
68
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 66
def inspect
"#<#{self.class}:#{object_id} exitcode=#{exitcode.inspect} stdout=#{stdout.inspect} stderr=#{stderr.inspect}>"
end
|
#nil? ⇒ Boolean
22
23
24
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 22
def nil?
@raw_output.nil?
end
|
#pending_threaded? ⇒ Boolean
30
31
32
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 30
def pending_threaded?
!@pending_threaded.nil?
end
|
#puts_combined ⇒ Object
34
35
36
37
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 34
def puts_combined
puts_stream(:stdout)
puts_stream(:stderr)
end
|
#puts_stream(stream_name) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 39
def puts_stream(stream_name)
return if @quiet || @raw_output.nil?
raise "Invalid stream: #{stream_name}" unless %i[stdout stderr].include?(stream_name)
stream = send(stream_name)
return if stream.nil? || stream.empty?
out_array = stream.split(%r{\n|\r\n}).map do |c|
chomped_c = c&.chomp
if chomped_c.nil? || chomped_c.strip.empty?
nil
else
format_output_string(chomped_c)
end
end
out_array.compact!
return if out_array.empty?
logger.info "#{stream_name.to_s.upcase}:\n#{out_array.join("\n")}"
end
|
#success? ⇒ Boolean
26
27
28
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 26
def success?
@exitcode&.zero?
end
|
#to_s ⇒ Object
60
61
62
63
64
|
# File 'lib/cem_win_spec/win_exec/output.rb', line 60
def to_s
return '' if @raw_output.nil?
format_output_string(@raw_output.to_s)
end
|