Class: Cutlass::BashResult
- Inherits:
-
Object
- Object
- Cutlass::BashResult
- Defined in:
- lib/cutlass/bash_result.rb
Overview
Value object containing the results of bash commands
result = BashResult.run(“echo ‘lol’) result.stdout # => ”lol“ result.status # => 0 result.success? # => true
Instance Attribute Summary collapse
- #status ⇒ Numeric readonly
- #stderr ⇒ String readonly
- #stdout ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#include?(value) ⇒ Boolean
Testing helper methods.
-
#initialize(stdout:, stderr:, status:) ⇒ BashResult
constructor
A new instance of BashResult.
- #match(value) ⇒ Object
- #match?(value) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(stdout:, stderr:, status:) ⇒ BashResult
Returns a new instance of BashResult.
28 29 30 31 32 |
# File 'lib/cutlass/bash_result.rb', line 28 def initialize(stdout:, stderr:, status:) @stdout = stdout @stderr = stderr @status = status.respond_to?(:exitstatus) ? status.exitstatus : status.to_i end |
Instance Attribute Details
#status ⇒ Numeric (readonly)
23 24 25 |
# File 'lib/cutlass/bash_result.rb', line 23 def status @status end |
#stderr ⇒ String (readonly)
20 21 22 |
# File 'lib/cutlass/bash_result.rb', line 20 def stderr @stderr end |
#stdout ⇒ String (readonly)
17 18 19 |
# File 'lib/cutlass/bash_result.rb', line 17 def stdout @stdout end |
Class Method Details
.run(command) ⇒ Object
11 12 13 14 |
# File 'lib/cutlass/bash_result.rb', line 11 def self.run(command) stdout, stderr, status = Open3.capture3(command) BashResult.new(stdout: stdout, stderr: stderr, status: status) end |
Instance Method Details
#failed? ⇒ Boolean
39 40 41 |
# File 'lib/cutlass/bash_result.rb', line 39 def failed? !success? end |
#include?(value) ⇒ Boolean
Testing helper methods
44 45 46 |
# File 'lib/cutlass/bash_result.rb', line 44 def include?(value) stdout.include?(value) end |
#match(value) ⇒ Object
52 53 54 |
# File 'lib/cutlass/bash_result.rb', line 52 def match(value) stdout.match(value) end |
#match?(value) ⇒ Boolean
48 49 50 |
# File 'lib/cutlass/bash_result.rb', line 48 def match?(value) stdout.match?(value) end |
#success? ⇒ Boolean
35 36 37 |
# File 'lib/cutlass/bash_result.rb', line 35 def success? @status == 0 end |