Class: Kobako::Snapshot

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

Overview

Kobako::Snapshot — per-invocation observable bundle returned from Kobako::Runtime#eval and #run.

The magnus class (see ext/kobako/src/snapshot.rs) carries seven raw readers: return_bytes, stdout_bytes, stdout_truncated, stderr_bytes, stderr_truncated, wall_time, memory_peak. This file reopens the class to add the Ruby-side helpers that pack those raw fields into the user-facing value objects Kobako::Capture and Kobako::Usage — the same shape Kobako::Sandbox exposes to the Host App.

Instance Method Summary collapse

Instance Method Details

#stderrObject

Wrap the stderr capture pair as a Kobako::Capture value object. Mirror of #stdout.



28
29
30
# File 'lib/kobako/snapshot.rb', line 28

def stderr
  Capture.new(bytes: stderr_bytes, truncated: stderr_truncated)
end

#stdoutObject

Wrap the stdout capture pair (stdout_bytes, stdout_truncated) as a Kobako::Capture value object. The byte content never carries a truncation sentinel; #truncated? is the only way to observe that the cap was hit.



22
23
24
# File 'lib/kobako/snapshot.rb', line 22

def stdout
  Capture.new(bytes: stdout_bytes, truncated: stdout_truncated)
end

#usageObject

Wrap the per-last-invocation usage pair (wall_time, memory_peak) as a Kobako::Usage value object.



34
35
36
# File 'lib/kobako/snapshot.rb', line 34

def usage
  Usage.new(wall_time: wall_time, memory_peak: memory_peak)
end