class OodSupport::User

A helper object used to query information about a system user from the local host

Public Class Methods

new(user = Process.user) click to toggle source

@param user [Integer, to_s] user id or name

# File lib/ood_support/user.rb, line 34
def initialize(user = Process.user)
  @passwd = user.is_a?(Integer) ? Etc.getpwuid(user) : Etc.getpwnam(user.to_s)
end

Public Instance Methods

<=>(other) click to toggle source

The comparison operator for sorting values @param other [#to_s] user to compare against @return [Integer] how users compare

# File lib/ood_support/user.rb, line 62
def <=>(other)
  name <=> other
end
eql?(other) click to toggle source

Checks whether two User objects have the same user as well as that the object is in the User class @param other [User] user to compare against @return [Boolean] whether same objects

# File lib/ood_support/user.rb, line 70
def eql?(other)
  self.class == other.class && self == other
end
group() click to toggle source

Provide primary group of user @return [Group] primary group of user

# File lib/ood_support/user.rb, line 49
def group
  groups.first
end
groups() click to toggle source

List of all groups that user belongs to @return [Array<Group>] list of groups user is in

# File lib/ood_support/user.rb, line 55
def groups
  @groups ||= get_groups
end
hash() click to toggle source

Generates a hash value for this object @return [Integer] hash value of object

# File lib/ood_support/user.rb, line 76
def hash
  [self.class, name].hash
end
in_group?(group) click to toggle source

Determine whether user is part of specified group @param group [Group] group to check @return [Boolean] whether user is in group

# File lib/ood_support/user.rb, line 41
def in_group?(group)
  groups.include? Group.new(group)
end
Also aliased as: member_of_group?
member_of_group?(group)
Alias for: in_group?
to_s() click to toggle source

Convert object to string using user name as string value @return [String] the user name

# File lib/ood_support/user.rb, line 82
def to_s
  name
end

Private Instance Methods

get_groups() click to toggle source

Use `id` to get list of groups as the /etc/group file can give erroneous results

# File lib/ood_support/user.rb, line 89
def get_groups
  `id -G #{name}`.split(' ').map {|g| Group.new(g.to_i)}
end