Class: Backspin::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/backspin/snapshot.rb

Overview

Represents a single captured execution snapshot.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def args
  @args
end

#command_typeObject (readonly)

Returns the value of attribute command_type.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def command_type
  @command_type
end

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def env
  @env
end

#recorded_atObject (readonly)

Returns the value of attribute recorded_at.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def recorded_at
  @recorded_at
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/backspin/snapshot.rb', line 6

def stderr
  @stderr
end

#stdoutObject (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

Returns:

  • (Boolean)


23
24
25
# File 'lib/backspin/snapshot.rb', line 23

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/backspin/snapshot.rb', line 19

def success?
  status.zero?
end

#to_hObject



27
28
29
# File 'lib/backspin/snapshot.rb', line 27

def to_h
  @serialized_hash
end