Class: Ace::Demo::Molecules::AggExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/demo/molecules/agg_executor.rb

Constant Summary collapse

INSTALL_URL =
"https://github.com/asciinema/agg"

Instance Method Summary collapse

Instance Method Details

#agg_available?(agg_bin: "agg") ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/ace/demo/molecules/agg_executor.rb', line 11

def agg_available?(agg_bin: "agg")
  _stdout, _stderr, status = Open3.capture3(agg_bin, "--version")
  status.success?
rescue Errno::ENOENT
  false
end

#run(cmd, agg_bin: "agg", chdir: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ace/demo/molecules/agg_executor.rb', line 18

def run(cmd, agg_bin: "agg", chdir: nil)
  effective_bin = cmd.first || agg_bin
  options = {}
  options[:chdir] = chdir if chdir
  stdout, stderr, status = Open3.capture3(*cmd, **options)
  result = Models::ExecutionResult.new(
    stdout: stdout.strip,
    stderr: stderr.strip,
    success: status.success?,
    exit_code: status.exitstatus
  )

  return result if result.success?

  raise AggExecutionError, "Agg execution failed: #{result.stderr}"
rescue Errno::ENOENT
  raise AggNotFoundError, "Agg not found (#{effective_bin}). Install: #{INSTALL_URL}"
end