Module: Wright::Util::User Private

Defined in:
lib/wright/util/user.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Various user utility functions.

Class Method Summary collapse

Class Method Details

.group_to_gid(group) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a group’s gid.

Examples:

Wright::Util::User.group_to_gid('root')
# => 0

Wright::Util::User.group_to_gid(0)
# => 0

Parameters:

  • group (String, Integer)

    the group’s name or gid

Returns:

  • (Integer)

    the integer gid of the given group or nil if group was nil



38
39
40
41
# File 'lib/wright/util/user.rb', line 38

def self.group_to_gid(group)
  return nil if group.nil?
  group.is_a?(String) ? Etc.getgrnam(group).gid : group.to_i
end

.owner_to_owner_group(owner) ⇒ Array<(String, String)>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Splits a colon-separated owner string into owner and group.

Examples:

Wright::Util::User.owner_to_owner_group('foo:bar')
# => ["foo", "bar"]

Wright::Util::User.owner_to_owner_group('foo')
# => ["foo", nil]

Wright::Util::User.owner_to_owner_group(23)
# => [23, nil]

Parameters:

  • owner (String)

    the owner string

Returns:

  • (Array<(String, String)>)

    the owner and group. Returns nil if no group was specified. Non-string owners are returned unmodified.

Raises:

  • (ArgumentError)

    if the owner string contains more than one colon



62
63
64
65
66
67
68
69
# File 'lib/wright/util/user.rb', line 62

def self.owner_to_owner_group(owner)
  group = nil
  return [owner, group] unless owner.is_a?(String)

  fail ArgumentError, "Invalid owner: '#{owner}'" if owner.count(':') > 1
  owner, group = owner.split(':')
  [owner, group]
end

.user_to_uid(user) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a user’s uid.

Examples:

Wright::Util::User.user_to_uid('root')
# => 0

Wright::Util::User.user_to_uid(0)
# => 0

Parameters:

  • user (String, Integer)

    the user’s name or uid

Returns:

  • (Integer)

    the integer uid of the given user or nil if user was nil



20
21
22
23
# File 'lib/wright/util/user.rb', line 20

def self.user_to_uid(user)
  return nil if user.nil?
  user.is_a?(String) ? Etc.getpwnam(user).uid : user.to_i
end