Class: NginxStage::User

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

Overview

A String-like Class that includes helper methods to better describe the user on the local system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ User

Returns a new instance of User.

Raises:

  • (InvalidUser)

    if user doesn’t exist on local system



35
36
37
38
39
40
41
# File 'lib/nginx_stage/user.rb', line 35

def initialize(user)
  @passwd = Etc.getpwnam user.to_s
  @group = Etc.getgrgid gid
  @groups = get_groups
rescue ArgumentError
  raise InvalidUser, "user doesn't exist: #{user}"
end

Instance Attribute Details

#groupsArray<String> (readonly)

List of all groups that user belongs to



31
32
33
# File 'lib/nginx_stage/user.rb', line 31

def groups
  @groups
end

Instance Method Details

#dirString

The user’s home directory



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

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

#gecosString

The user’s real name



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

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

#gidInteger

The user’s group id



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

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

#groupString

User’s primary group name



45
46
47
# File 'lib/nginx_stage/user.rb', line 45

def group
  @group.name
end

#group_memArray<String>

Members of user’s primary group



51
52
53
# File 'lib/nginx_stage/user.rb', line 51

def group_mem
  @group.mem
end

#nameString

The user name



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

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

#shellString

The user’s shell



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

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

#to_sString

Convert object to string using user name as string value



57
58
59
# File 'lib/nginx_stage/user.rb', line 57

def to_s
  @passwd.name
end

#to_strString

This object is string-like and returns the user name when treated as a string



64
65
66
# File 'lib/nginx_stage/user.rb', line 64

def to_str
  @passwd.name
end

#uidInteger

The user’s id



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

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