Class: Ruuuby::MetaData::RuuubyAPI

Inherits:
RuuubyAPIComponent show all
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

#versionable

Instance Method Summary collapse

Methods inherited from RuuubyAPIComponent

#version

Methods inherited from RuuubyEngineComponent

#∅?

Constructor Details

#initialize(engine, default_timeout) ⇒ RuuubyAPI

Returns a new instance of RuuubyAPI.

Parameters:

  • engine (*)
  • default_timeout (Integer)


21
22
23
24
25
26
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 21

def initialize(engine, default_timeout)
  

Instance Method Details

#_calculate_versionObject



77
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 77

def _calculate_version; 1337; end

#curl_get(url_resource, optional_save_as_path = '') ⇒ Object

Parameters:

  • url_resource (String)
  • optional_save_as_path (String) (defaults to: '')

See Also:



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_ttyObject

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

Parameters:

Raises:

  • (ArgumentError)


72
73
74
75
# File 'lib/ruuuby/ruuuby/ruuuby_api.rb', line 72

def pid_terminate(pid_id)
  

#run_apple_script!(cmd) ⇒ String, Array

Parameters:

Returns:

Raises:

  • (ArgumentError)


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