Class: Rpremote::Runner
- Inherits:
-
Object
- Object
- Rpremote::Runner
- Defined in:
- lib/rpremote/runner.rb,
sig/rpremote.rbs
Constant Summary collapse
- REMOTE_DIRECTORY =
"/home"
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#timeout ⇒ Float
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(io, timeout: Shell::DEFAULT_TIMEOUT, modem_class: PicoModem, shell_class: Shell, path_factory: nil) ⇒ Runner
constructor
A new instance of Runner.
- #run(data, output: nil) ⇒ String
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
#io ⇒ Object (readonly)
Returns the value of attribute io.
7 8 9 |
# File 'lib/rpremote/runner.rb', line 7 def io @io end |
#timeout ⇒ Float (readonly)
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/rpremote/runner.rb', line 7 def timeout @timeout end |
Instance Method Details
#run(data, output: nil) ⇒ 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 |