Module: Shells::BashCommon

Included in:
SerialSession, SshSession
Defined in:
lib/shells/bash_common.rb

Overview

Provides some common functionality for bash-like shells.

Instance Method Summary collapse

Instance Method Details

#read_file(path, use_method = nil) ⇒ Object

Reads from a file on the device.



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

def read_file(path, use_method = nil)
  if use_method
    use_method = use_method.to_sym
    raise ArgumentError, "use_method (#{use_method.inspect}) is not a valid method." unless file_methods.include?(use_method)
    raise Shells::ShellError, "The #{use_method} binary is not available with this shell." unless which(use_method)
    send "read_file_#{use_method}", path
  elsif default_file_method
    return send "read_file_#{default_file_method}", path
  else
    raise Shells::ShellError, 'No supported binary to encode/decode files.'
  end
end

#write_file(path, data, use_method = nil) ⇒ Object

Writes to a file on the device.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shells/bash_common.rb', line 25

def write_file(path, data, use_method = nil)
  if use_method
    use_method = use_method.to_sym
    raise ArgumentError, "use_method (#{use_method.inspect}) is not a valid method." unless file_methods.include?(use_method)
    raise Shells::ShellError, "The #{use_method} binary is not available with this shell." unless which(use_method)
    send "write_file_#{use_method}", path, data
  elsif default_file_method
    return send "write_file_#{default_file_method}", path, data
  else
    raise Shells::ShellError, 'No supported binary to encode/decode files.'
  end
end