class OodSupport::User
A helper object used to query information about a system user from the local host
Public Class Methods
@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
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
Provide primary group of user @return [Group] primary group of user
# File lib/ood_support/user.rb, line 49 def group groups.first end
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
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
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
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
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