Class: OodSupport::User

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/ood_support/user.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(user = Process.user) ⇒ User

Returns a new instance of User.

Parameters:

  • user (Fixnum, #to_s) (defaults to: Process.user)

    user id or name


34
35
36
# File 'lib/ood_support/user.rb', line 34

def initialize(user = Process.user)
  @passwd = user.is_a?(Fixnum) ? Etc.getpwuid(user) : Etc.getpwnam(user.to_s)
end

Instance Method Details

#<=>(other) ⇒ Fixnum

The comparison operator for sorting values

Parameters:

  • other (#to_s)

    user to compare against

Returns:

  • (Fixnum)

    how users compare


62
63
64
# File 'lib/ood_support/user.rb', line 62

def <=>(other)
  name <=> other
end

#dirString Also known as: home

The user's home directory

Returns:

  • (String)

    the home path


27
# File 'lib/ood_support/user.rb', line 27

delegate [:name, :uid, :gecos, :dir, :shell] => :@passwd

#eql?(other) ⇒ Boolean

Checks whether two User objects have the same user as well as that the object is in the User class

Parameters:

  • other (User)

    user to compare against

Returns:

  • (Boolean)

    whether same objects


70
71
72
# File 'lib/ood_support/user.rb', line 70

def eql?(other)
  self.class == other.class && self == other
end

#gecosString

The user's real name

Returns:

  • (String)

    the real name


27
# File 'lib/ood_support/user.rb', line 27

delegate [:name, :uid, :gecos, :dir, :shell] => :@passwd

#groupGroup

Provide primary group of user

Returns:

  • (Group)

    primary group of user


49
50
51
# File 'lib/ood_support/user.rb', line 49

def group
  groups.first
end

#groupsArray<String>

List of all groups that user belongs to

Returns:

  • (Array<String>)

    list of groups user is in


55
56
57
# File 'lib/ood_support/user.rb', line 55

def groups
  @groups ||= get_groups
end

#hashFixnum

Generates a hash value for this object

Returns:

  • (Fixnum)

    hash value of object


76
77
78
# File 'lib/ood_support/user.rb', line 76

def hash
  [self.class, name].hash
end

#in_group?(group) ⇒ Boolean Also known as: member_of_group?

Determine whether user is part of specified group

Parameters:

  • group (Group)

    group to check

Returns:

  • (Boolean)

    whether user is in group


41
42
43
# File 'lib/ood_support/user.rb', line 41

def in_group?(group)
  groups.include? Group.new(group)
end

#nameString

The user name

Returns:

  • (String)

    the user name


27
# File 'lib/ood_support/user.rb', line 27

delegate [:name, :uid, :gecos, :dir, :shell] => :@passwd

#shellString

The user's shell

Returns:

  • (String)

    the shell


27
# File 'lib/ood_support/user.rb', line 27

delegate [:name, :uid, :gecos, :dir, :shell] => :@passwd

#to_sString

Convert object to string using user name as string value

Returns:

  • (String)

    the user name


82
83
84
# File 'lib/ood_support/user.rb', line 82

def to_s
  name
end

#uidInteger Also known as: id

The user's id

Returns:

  • (Integer)

    the user id


27
# File 'lib/ood_support/user.rb', line 27

delegate [:name, :uid, :gecos, :dir, :shell] => :@passwd