Inline type annotations for User.

This commit is contained in:
Markus Reiter 2020-10-10 15:53:14 +02:00
parent fc7a34585f
commit 059122c724
2 changed files with 5 additions and 11 deletions

View File

@ -1,11 +0,0 @@
# typed: strict
class User < SimpleDelegator
include Kernel
sig { returns(T::Boolean) }
def gui?; end
sig { returns(T.nilable(T.attached_class)) }
def self.current; end
end

View File

@ -10,7 +10,11 @@ require "system_command"
#
# @api private
class User < SimpleDelegator
include Kernel
extend T::Sig
# Return whether the user has an active GUI session.
sig { returns(T::Boolean) }
def gui?
out, _, status = system_command "who"
return false unless status.success?
@ -21,6 +25,7 @@ class User < SimpleDelegator
end
# Return the current user.
sig { returns(T.nilable(T.attached_class)) }
def self.current
return @current if defined?(@current)