Class: Backspin::Command
- Inherits:
-
Object
- Object
- Backspin::Command
- Defined in:
- lib/backspin/command.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#method_class ⇒ Object
readonly
Returns the value of attribute method_class.
-
#recorded_at ⇒ Object
readonly
Returns the value of attribute recorded_at.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.from_h(data) ⇒ Object
Create from hash (for loading from YAML).
Instance Method Summary collapse
-
#initialize(method_class:, args:, stdout: nil, stderr: nil, status: nil, result: nil, recorded_at: nil) ⇒ Command
constructor
A new instance of Command.
- #status ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
-
#to_h(filter: nil) ⇒ Object
Convert to hash for YAML serialization.
Constructor Details
#initialize(method_class:, args:, stdout: nil, stderr: nil, status: nil, result: nil, recorded_at: nil) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 |
# File 'lib/backspin/command.rb', line 9 def initialize(method_class:, args:, stdout: nil, stderr: nil, status: nil, result: nil, recorded_at: nil) @method_class = method_class @args = args @recorded_at = recorded_at # Accept either a CommandResult or individual stdout/stderr/status @result = result || CommandResult.new(stdout: stdout || "", stderr: stderr || "", status: status || 0) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/backspin/command.rb', line 7 def args @args end |
#method_class ⇒ Object (readonly)
Returns the value of attribute method_class.
7 8 9 |
# File 'lib/backspin/command.rb', line 7 def method_class @method_class end |
#recorded_at ⇒ Object (readonly)
Returns the value of attribute recorded_at.
7 8 9 |
# File 'lib/backspin/command.rb', line 7 def recorded_at @recorded_at end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/backspin/command.rb', line 7 def result @result end |
Class Method Details
.from_h(data) ⇒ Object
Create from hash (for loading from YAML)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/backspin/command.rb', line 48 def self.from_h(data) # Determine method class from command_type method_class = case data["command_type"] when "Open3::Capture3" Open3::Capture3 when "Kernel::System" ::Kernel::System when "Backspin::Capturer" Backspin::Capturer else # Default to capture3 for backwards compatibility Open3::Capture3 end new( method_class: method_class, args: data["args"], stdout: data["stdout"], stderr: data["stderr"], status: data["status"], recorded_at: data["recorded_at"] ) end |
Instance Method Details
#status ⇒ Object
26 27 28 |
# File 'lib/backspin/command.rb', line 26 def status @result.status end |
#stderr ⇒ Object
22 23 24 |
# File 'lib/backspin/command.rb', line 22 def stderr @result.stderr end |
#stdout ⇒ Object
18 19 20 |
# File 'lib/backspin/command.rb', line 18 def stdout @result.stdout end |
#to_h(filter: nil) ⇒ Object
Convert to hash for YAML serialization
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/backspin/command.rb', line 31 def to_h(filter: nil) data = { "command_type" => @method_class.name, "args" => scrub_args(@args), "stdout" => Backspin.scrub_text(@result.stdout), "stderr" => Backspin.scrub_text(@result.stderr), "status" => @result.status, "recorded_at" => @recorded_at } # Apply filter if provided data = filter.call(data) if filter data end |