Class: Beaker::Result
- Inherits:
-
Object
- Object
- Beaker::Result
- Defined in:
- lib/beaker/result.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
-
#host ⇒ Object
Returns the value of attribute host.
-
#output ⇒ Object
Returns the value of attribute output.
-
#raw_output ⇒ Object
Returns the value of attribute raw_output.
-
#raw_stderr ⇒ Object
Returns the value of attribute raw_stderr.
-
#raw_stdout ⇒ Object
Returns the value of attribute raw_stdout.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #convert(string) ⇒ Object
- #exit_code_in?(range) ⇒ Boolean
-
#finalize! ⇒ Object
Ruby assumes chunked data (like something it receives from Net::SSH) to be binary (ASCII-8BIT).
- #formatted_output(limit = 10) ⇒ Object
-
#initialize(host, cmd) ⇒ Result
constructor
A new instance of Result.
- #log(logger) ⇒ Object
- #normalize_line_endings(string) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(host, cmd) ⇒ Result
Returns a new instance of Result.
6 7 8 9 10 11 12 13 |
# File 'lib/beaker/result.rb', line 6 def initialize(host, cmd) @host = host @cmd = cmd @stdout = '' @stderr = '' @output = '' @exit_code = nil end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def cmd @cmd end |
#exit_code ⇒ Object
Returns the value of attribute exit_code.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def exit_code @exit_code end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def host @host end |
#output ⇒ Object
Returns the value of attribute output.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def output @output end |
#raw_output ⇒ Object
Returns the value of attribute raw_output.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_output @raw_output end |
#raw_stderr ⇒ Object
Returns the value of attribute raw_stderr.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_stderr @raw_stderr end |
#raw_stdout ⇒ Object
Returns the value of attribute raw_stdout.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_stdout @raw_stdout end |
#stderr ⇒ Object
Returns the value of attribute stderr.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def stdout @stdout end |
Instance Method Details
#convert(string) ⇒ Object
34 35 36 37 38 |
# File 'lib/beaker/result.rb', line 34 def convert string # Remove invalid and undefined UTF-8 character encodings string.to_s.force_encoding('UTF-8') string.to_s.chars.select { |i| i.valid_encoding? }.join end |
#exit_code_in?(range) ⇒ Boolean
48 49 50 |
# File 'lib/beaker/result.rb', line 48 def exit_code_in?(range) range.include?(@exit_code) end |
#finalize! ⇒ Object
Ruby assumes chunked data (like something it receives from Net::SSH) to be binary (ASCII-8BIT). We need to gather all chunked data and then re-encode it as the default encoding it assumes for external text (ie our test files and the strings they’re trying to match Net::SSH’s output from) This is also the lowest overhead place to normalize line endings, IIRC
21 22 23 24 25 26 27 28 |
# File 'lib/beaker/result.rb', line 21 def finalize! @raw_stdout = @stdout @stdout = normalize_line_endings(convert(@stdout)) @raw_stderr = @stderr @stderr = normalize_line_endings(convert(@stderr)) @raw_output = @output @output = normalize_line_endings(convert(@output)) end |
#formatted_output(limit = 10) ⇒ Object
44 45 46 |
# File 'lib/beaker/result.rb', line 44 def formatted_output(limit = 10) @output.split("\n").last(limit).collect { |x| "\t" + x }.join("\n") end |
#log(logger) ⇒ Object
40 41 42 |
# File 'lib/beaker/result.rb', line 40 def log(logger) logger.debug "Exited: #{exit_code}" unless exit_code == 0 or !exit_code end |
#normalize_line_endings(string) ⇒ Object
30 31 32 |
# File 'lib/beaker/result.rb', line 30 def normalize_line_endings string return string.gsub(/\r\n?/, "\n") end |
#success? ⇒ Boolean
52 53 54 |
# File 'lib/beaker/result.rb', line 52 def success? exit_code == 0 end |