module Diffend::LocalContext::Host
Module responsible for building host information from local context
Constants
- WINDOWS_REGEXP
Regexp that checks if we're running under Windows
Public Class Methods
call()
click to toggle source
Build host information
@return [Hash]
# File lib/diffend/local_context/host.rb, line 19 def call uname = Etc.uname { 'command' => command, 'name' => uname[:nodename], 'system' => { 'machine' => uname[:machine], 'name' => uname[:sysname], 'release' => uname[:release], 'version' => uname[:version] }, 'tags' => tags, 'user' => Etc.getpwuid(Process.uid)&.name || ENV['USERNAME'], 'pid' => Process.pid }.freeze end
Private Class Methods
clean(str)
click to toggle source
@param str [String] that we want to clean and truncate
# File lib/diffend/local_context/host.rb, line 91 def clean(str) str .dup .gsub(/[[:space:]]+/, ' ') .strip[0...255] end
command()
click to toggle source
Build host command information
@return [Hash]
# File lib/diffend/local_context/host.rb, line 42 def command if File.exist?($PROGRAM_NAME) if defined?(JRUBY_VERSION) || WINDOWS_REGEXP =~ RUBY_PLATFORM name = $PROGRAM_NAME.split('/').last.strip command = "#{name} #{ARGV.join(' ')}" else array = `ps -p #{Process.pid} -o command=`.strip.split(' ') array.shift if array.first.end_with?('bin/ruby') name = array.shift.split('/').last.strip command = "#{name} #{array.join(' ')}" end { 'name' => clean(command), 'title' => '' } else { 'name' => clean(ARGV.join(' ')), 'title' => clean($PROGRAM_NAME) } end end