Class: Eksekuter

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

Overview

Class that command execution is delegated to by Eksek.

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ Eksekuter

Returns a new instance of Eksekuter.

Parameters:

  • logger (Logger) (defaults to: nil)


10
11
12
13
14
15
# File 'lib/eksekuter.rb', line 10

def initialize logger: nil
  @logger = logger
  @stdout_buffer = nil
  @stderr_buffer = nil
  @stdin_buffer = nil
end

Instance Method Details

#capture(*args, **opts) ⇒ Object

Like Eksekuter#exec but the :out and :err options are ignored; instead the output is attached to the EksekResult object returned. Returns an EksekResult object which getters :stdout and :stderr containing the corresponding output of the spawned process.

Returns:

  • EksekResult



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/eksekuter.rb', line 31

def capture *args, **opts
  env, cmd = split_env_and_cmd(args)
  out_read, out_write = IO.pipe
  err_read, err_write = IO.pipe
  opts2 = opts.merge(out: out_write, err: err_write)
  params = { env: env, cmd: cmd, opts: opts2 }
  process_status = spawn_and_get_status(params)
  out_write.close
  err_write.close
  assemble_result(params, process_status, out_read, err_read)
end

#exec(*args, **opts) ⇒ Object

Wraps around Kernel#spawn so that the return value is an EksekResult.

Returns:

  • EksekResult



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

def exec *args, **opts
  env, cmd = split_env_and_cmd(args)
  params = { env: env, cmd: cmd, opts: opts }
  process_status = spawn_and_get_status(params)
  assemble_result(params, process_status)
end