Class: Ruuuby::MetaData::RuuubyAPI
- Inherits:
-
RuuubyAPIComponent
- Object
- RuuubyEngineComponent
- RuuubyAPIComponent
- Ruuuby::MetaData::RuuubyAPI
- Defined in:
- lib/ruuuby/ruuuby/ruuuby_api.rb
Overview
| tty | teletype | “in UNIX, /dev/tty* is any device that acts like a teletype, ie, a terminal” | pty | pseudo-teletype | “device entry that acts like a terminal to the process performing I/O, but is managed by something else”
‘💎.engine.api`
Instance Attribute Summary
Attributes inherited from RuuubyEngineComponent
Instance Method Summary collapse
- #_calculate_version ⇒ Object
- #curl_get(url_resource, optional_save_as_path = '') ⇒ Object
-
#get_tty ⇒ Object
printer options [null] no output [pretty] colorful output [progress] minimal output with green dot for success and F for failure [quiet] only output actual command stdout and stderr.
-
#initialize(engine, default_timeout) ⇒ RuuubyAPI
constructor
A new instance of RuuubyAPI.
- #pid_terminate(pid_id) ⇒ Object
- #run_apple_script!(cmd) ⇒ String, Array
- #run_cmd(cmd) ⇒ Object
-
#run_cmd!(cmd) ⇒ Object
| error code | description | | ———- | ————————– | | 1 | general error | | 2 | mis-used shell built-ins | | 126 | cmd invoked cannot execute | | 127 | cmd not found | | 128 | invalid argument to exit | | 128 + n | fatal error signal
n| | 130 | terminated w/ Control-C | | 255* | exit status out of range |.
Methods inherited from RuuubyAPIComponent
Methods inherited from RuuubyEngineComponent
Constructor Details
#initialize(engine, default_timeout) ⇒ RuuubyAPI
Returns a new instance of RuuubyAPI.
21 22 23 24 25 26 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 21 def initialize(engine, default_timeout) |
Instance Method Details
#_calculate_version ⇒ Object
77 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 77 def _calculate_version; 1337; end |
#curl_get(url_resource, optional_save_as_path = '') ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 90 def curl_get(url_resource, optional_save_as_path='') |
#get_tty ⇒ Object
printer options
- null
-
no output
- pretty
-
colorful output
- progress
-
minimal output with green dot for success and F for failure
- quiet
-
only output actual command stdout and stderr
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 106 def get_tty if @gem_tty.nil? if @engine.logger.nil? @gem_tty = ::TTY::Command.new(printer: :pretty) #(printer: :pretty) #printer: :null else @gem_tty = ::TTY::Command.new(output: @engine.logger, color: false) end end @gem_tty end |
#pid_terminate(pid_id) ⇒ Object
72 73 74 75 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 72 def pid_terminate(pid_id) |
#run_apple_script!(cmd) ⇒ String, Array
64 65 66 67 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 64 def run_apple_script!(cmd) |
#run_cmd(cmd) ⇒ Object
28 29 30 31 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 28 def run_cmd(cmd) out, err = self.get_tty.run(cmd, timeout: @default_timeout, pty: false) return out, err end |
#run_cmd!(cmd) ⇒ Object
| error code | description | | ———- | ————————– | | 1 | general error | | 2 | mis-used shell built-ins | | 126 | cmd invoked cannot execute | | 127 | cmd not found | | 128 | invalid argument to exit | | 128 + n | fatal error signal n | | 130 | terminated w/ Control-C | | 255* | exit status out of range |
TODO: useful cmd: ps -lww -p <PID>
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 47 def run_cmd!(cmd) out, err = self.get_tty.run(cmd, timeout: @default_timeout, pty: false) unless err.empty? raise "cmd{#{cmd.to_s}} encountered error{#{err.to_s}}" end if cmd.str? || cmd.ary? out.clean else out end end |