Class: Binaryen::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/binaryen/command.rb

Constant Summary collapse

DEFAULT_MAX_OUTPUT_SIZE =

256 MiB

256 * 1024 * 1024 * 1024
DEFAULT_TIMEOUT =
10
DEFAULT_ARGS_FOR_COMMAND =
{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(cmd, timeout: DEFAULT_TIMEOUT, max_output_size: DEFAULT_MAX_OUTPUT_SIZE, ignore_missing: false) ⇒ Command

Returns a new instance of Command.



12
13
14
15
16
17
# File 'lib/binaryen/command.rb', line 12

def initialize(cmd, timeout: DEFAULT_TIMEOUT, max_output_size: DEFAULT_MAX_OUTPUT_SIZE, ignore_missing: false)
  @cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
  @timeout = timeout
  @default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
  @max_output_size = max_output_size
end

Instance Method Details

#run(*arguments, stdin: nil, stderr: nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/binaryen/command.rb', line 19

def run(*arguments, stdin: nil, stderr: nil)
  args = [@cmd] + arguments + @default_args
  Timeout.timeout(@timeout) do
    spawn_command(*args, stderr: stderr, stdin: stdin)
  end
end