Skip to content
Kward Search API index

Class: Kward::Sandbox::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/sandbox/command_runner.rb

Overview

Base command runner. Platform runners provide an argv that is then executed through LocalCommandRunner, preserving Kward's timeout and cancellation behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policy:, capabilities:) ⇒ CommandRunner

Returns a new instance of CommandRunner.



9
10
11
12
# File 'lib/kward/sandbox/command_runner.rb', line 9

def initialize(policy:, capabilities:)
  @policy = policy
  @capabilities = capabilities
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



14
15
16
# File 'lib/kward/sandbox/command_runner.rb', line 14

def capabilities
  @capabilities
end

#policyObject (readonly)

Returns the value of attribute policy.



14
15
16
# File 'lib/kward/sandbox/command_runner.rb', line 14

def policy
  @policy
end

Instance Method Details

#command_argv(command, cwd:) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/kward/sandbox/command_runner.rb', line 23

def command_argv(command, cwd:)
  raise NotImplementedError, "#{self.class} must implement #command_argv"
end

#run(command, cwd:, timeout_seconds:, max_output_bytes:, cancellation: nil, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/kward/sandbox/command_runner.rb', line 16

def run(command, cwd:, timeout_seconds:, max_output_bytes:, cancellation: nil, &block)
  LocalCommandRunner.new(
    timeout_seconds: timeout_seconds,
    max_output_bytes: max_output_bytes
  ).run(*command_argv(command, cwd: cwd), cwd: cwd, cancellation: cancellation, &block)
end