Class: User Private

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
T::Sig
Includes:
SystemCommand::Mixin
Defined in:
utils/user.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A system user.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Class Method Details

.currentT.attached_class?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Return the current user.

Returns:

  • (T.attached_class, nil)


30
31
32
33
34
35
36
37
# File 'utils/user.rb', line 30

def self.current
  return @current if defined?(@current)

  pwuid = Etc.getpwuid(Process.euid)
  return if pwuid.nil?

  @current = new(pwuid.name)
end

Instance Method Details

#gui?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Return whether the user has an active GUI session.

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'utils/user.rb', line 19

def gui?
  out, _, status = system_command "who"
  return false unless status.success?

  out.lines
     .map(&:split)
     .any? { |user, type,| user == self && type == "console" }
end