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


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


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


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


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


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

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

#groupGroup

Provide 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


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


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


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


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

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

#shellString

The user's 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


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


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

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