Class: Backspin::Snapshot
- Inherits:
-
Object
- Object
- Backspin::Snapshot
- Defined in:
- lib/backspin/snapshot.rb
Overview
Represents a single captured execution snapshot.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command_type ⇒ Object
readonly
Returns the value of attribute command_type.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#recorded_at ⇒ Object
readonly
Returns the value of attribute recorded_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(command_type:, args:, env: nil, stdout: "", stderr: "", status: 0, recorded_at: nil) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(command_type:, args:, env: nil, stdout: "", stderr: "", status: 0, recorded_at: nil) ⇒ Snapshot
Returns a new instance of Snapshot.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/backspin/snapshot.rb', line 8 def initialize(command_type:, args:, env: nil, stdout: "", stderr: "", status: 0, recorded_at: nil) @command_type = command_type @args = sanitize_args(args) @env = env.nil? ? nil : sanitize_env(env) @stdout = Backspin.scrub_text((stdout || "").dup).freeze @stderr = Backspin.scrub_text((stderr || "").dup).freeze @status = status || 0 @recorded_at = recorded_at.nil? ? nil : recorded_at.dup.freeze @serialized_hash = build_serialized_hash end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def args @args end |
#command_type ⇒ Object (readonly)
Returns the value of attribute command_type.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def command_type @command_type end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def env @env end |
#recorded_at ⇒ Object (readonly)
Returns the value of attribute recorded_at.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def recorded_at @recorded_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/backspin/snapshot.rb', line 6 def stdout @stdout end |
Class Method Details
.from_h(data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/backspin/snapshot.rb', line 31 def self.from_h(data) command_type = case data["command_type"] when "Open3::Capture3" Open3::Capture3 when "Backspin::Capturer" Backspin::Capturer else raise RecordFormatError, "Unknown command type: #{data["command_type"]}" end new( command_type: command_type, args: data["args"], env: data["env"], stdout: data["stdout"], stderr: data["stderr"], status: data["status"], recorded_at: data["recorded_at"] ) end |
Instance Method Details
#failure? ⇒ Boolean
23 24 25 |
# File 'lib/backspin/snapshot.rb', line 23 def failure? !success? end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/backspin/snapshot.rb', line 19 def success? status.zero? end |
#to_h ⇒ Object
27 28 29 |
# File 'lib/backspin/snapshot.rb', line 27 def to_h @serialized_hash end |