Class: Rpremote::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rpremote/runner.rb,
sig/rpremote.rbs

Constant Summary collapse

REMOTE_DIRECTORY =

Returns:

  • (String)
"/home"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, timeout: Shell::DEFAULT_TIMEOUT, modem_class: PicoModem, shell_class: Shell, path_factory: nil) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpremote/runner.rb', line 9

def initialize(
  io,
  timeout: Shell::DEFAULT_TIMEOUT,
  modem_class: PicoModem,
  shell_class: Shell,
  path_factory: nil
)
  @io = io
  @timeout = timeout
  @modem_class = modem_class
  @shell_class = shell_class
  @path_factory = path_factory || method(:temporary_path)
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.

Returns:

  • (Object)


7
8
9
# File 'lib/rpremote/runner.rb', line 7

def io
  @io
end

#timeoutFloat (readonly)

Returns the value of attribute timeout.

Returns:

  • (Float)


7
8
9
# File 'lib/rpremote/runner.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#run(data, output: nil) ⇒ String

Parameters:

  • data (String)
  • output: (IO, nil) (defaults to: nil)

Returns:

  • (String)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rpremote/runner.rb', line 23

def run(data, output: nil)
  remote_path = @path_factory.call
  shell = @shell_class.new(io, timeout: timeout)
  shell.synchronize!
  @modem_class.new(io, timeout: timeout).upload(remote_path, data)
  shell.synchronize!
  shell_ready = true
  output ? shell.execute("./#{File.basename(remote_path)}", output: output) : shell.execute("./#{File.basename(remote_path)}")
ensure
  cleanup(shell, remote_path) if shell_ready && remote_path
end