class QB::IPC::STDIO::Client::Connection
@todo document Connection
class.
Attributes
TODO document `env_var_name` attribute.
@return [String]
TODO document `global_original` attribute.
@return [attr_type]
@return [Connection]
TODO document `name` attribute.
@return [Symbol]
TODO document `path` attribute.
@return [Pathname?]
TODO document `socket` attribute.
@return [UNIXSocket?]
@return [Connection]
@return [Connection]
@return [Connection]
TODO document `type` attribute.
@return [:in | :out]
Public Class Methods
Instantiate a new `Connection`.
# File lib/qb/ipc/stdio/client.rb, line 101 def initialize name:, type: @name = name @type = type @global_original = nil @path = nil @socket = nil @env_var_name = QB::IPC::STDIO.path_env_var_name name end
Public Instance Methods
# File lib/qb/ipc/stdio/client.rb, line 119 def connect! if connected? raise "#{ inspect } is already connected!" end if get_path! @global_original = global_get @socket = UNIXSocket.new path.to_s global_set! socket end end
# File lib/qb/ipc/stdio/client.rb, line 132 def disconnect! return unless connected? logger.debug "Disconnecting...", name: name, socket: socket, global_original: global_original # Restore the original global and `nil` it out (if we have one) if global_original global_set! global_original @global_original = nil end # Flush the socket if it's an out-bound socket.flush if type == :out # And close and `nil` it socket.close @socket = nil end
Protected Instance Methods
@return [Array<Connection>]
The three {Connection} instances.
# File lib/qb/ipc/stdio/client.rb, line 246 def connections [ @stdin, @stdout, @stderr, @log ] end
Get the socket path from the ENV and set `@path` to it (which may be `nil` if we don't find anything).
@return [Pathname?]
# File lib/qb/ipc/stdio/client.rb, line 163 def get_path! @path = ENV[ env_var_name ] @path = path.to_pn if path path end
Get the IO global (`$stdin`, `$stdout`, `$stderr`) if {#name} lines up for one of those.
@return [IO?]
# File lib/qb/ipc/stdio/client.rb, line 175 def global_get case name when :in $stdin when :out $stdout when :err $stderr end end
Set the IO global (`$stdin`, `$stdout`, `$stderr`) to `value` if {#name} lines up for one of those.
@param [IO] value @return [void]
# File lib/qb/ipc/stdio/client.rb, line 193 def global_set! value case name when :in $stdin = value when :out $stdout = value when :err $stderr = value end end