Class: NginxStage::User
- Inherits:
-
Object
- Object
- NginxStage::User
- 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
-
#groups ⇒ Array<String>
readonly
List of all groups that user belongs to.
Instance Method Summary collapse
-
#dir ⇒ String
The user’s home directory.
-
#gecos ⇒ String
The user’s real name.
-
#gid ⇒ Integer
The user’s group id.
-
#group ⇒ String
User’s primary group name.
-
#group_mem ⇒ Array<String>
Members of user’s primary group.
-
#initialize(user) ⇒ User
constructor
A new instance of User.
-
#name ⇒ String
The user name.
-
#shell ⇒ String
The user’s shell.
-
#to_s ⇒ String
Convert object to string using user name as string value.
-
#to_str ⇒ String
This object is string-like and returns the user name when treated as a string.
-
#uid ⇒ Integer
The user’s id.
Constructor Details
#initialize(user) ⇒ User
Returns a new instance of User.
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
#groups ⇒ Array<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
#dir ⇒ String
The user’s home directory
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |
#gecos ⇒ String
The user’s real name
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |
#gid ⇒ Integer
The user’s group id
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |
#group ⇒ String
User’s primary group name
45 46 47 |
# File 'lib/nginx_stage/user.rb', line 45 def group @group.name end |
#group_mem ⇒ Array<String>
Members of user’s primary group
51 52 53 |
# File 'lib/nginx_stage/user.rb', line 51 def group_mem @group.mem end |
#name ⇒ String
The user name
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |
#shell ⇒ String
The user’s shell
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |
#to_s ⇒ String
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_str ⇒ String
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 |
#uid ⇒ Integer
The user’s id
27 |
# File 'lib/nginx_stage/user.rb', line 27 delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd |