Class: User Private

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


26
27
28
29
30
31
32
33
# File 'utils/user.rb', line 26

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

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

  @current = T.let(new(pwuid.name), T.nilable(T.attached_class))
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)


15
16
17
18
19
20
21
22
# File 'utils/user.rb', line 15

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

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