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
This method behaves differently when given a string instance, subclass or something else.
- #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
This method behaves differently when given a string instance, subclass or something else. The latter two cases should be deprecated.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/beaker/result.rb', line 36 def convert(string) # guard against nil, which never worked on accident raise TypeError, "Beaker::Result#convert cannot convert nil to a String" if string.nil? unless string.instance_of?(String) # For a string subclass, `string.to_s` returns a copy, so calling # `force_encoding` on it was meaningless. return string.to_s.scrub('') end # Data collected from the connection is binary (ASCII-8BIT). In that # encoding, every byte is a valid character, so we tag the string as UTF-8 string.force_encoding('UTF-8') # And remove invalid and undefined UTF-8 character encodings. string.scrub('') end |
#exit_code_in?(range) ⇒ Boolean
62 63 64 |
# File 'lib/beaker/result.rb', line 62 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
58 59 60 |
# File 'lib/beaker/result.rb', line 58 def formatted_output(limit = 10) @output.split("\n").last(limit).collect { |x| "\t" + x }.join("\n") end |
#log(logger) ⇒ Object
54 55 56 |
# File 'lib/beaker/result.rb', line 54 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
66 67 68 |
# File 'lib/beaker/result.rb', line 66 def success? exit_code == 0 end |