Class: OSC::Machete::User Deprecated
- Inherits:
-
Object
- Object
- OSC::Machete::User
- Defined in:
- lib/osc/machete/user.rb
Overview
Please use OodSupport::User instead.
Class that maintains the name and home identifiers of a User. Helper methods provided use the Etc module underneath.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.from_uid(uid) ⇒ User
factory method to produce a User from specified uid.
Instance Method Summary collapse
-
#groups ⇒ Array
get sorted list of group ids that user is part of by inspecting the /etc/group file there is also a ruby impl of this.
-
#home ⇒ String
The home directory path of the user.
-
#initialize(username = Etc.getpwuid.name) ⇒ User
constructor
default user is the username of the current process.
-
#member_of_group?(group) ⇒ Boolean
Determine if user is member of specified group.
-
#projects ⇒ Array<String>
get list of projects the user is part of FIXME: OSC specific.
Constructor Details
#initialize(username = Etc.getpwuid.name) ⇒ User
default user is the username of the current process
FIXME: is this true? Etc.getpwuid claims to use the default value from the Passwd struct: docs.ruby-lang.org/en/2.0.0/Etc.html#Passwd could this ever be different from Process.gid? Should we provide constructors for a User object for the given uid instead of username, or in Process do OSC::Machete::User.new(Etc.getpwuid.name(Process.gid)) Or should the default be OSC::Machete::User.from_uid(Process.uid) Is there ever a difference between the two?
21 22 23 24 25 |
# File 'lib/osc/machete/user.rb', line 21 def initialize(username = Etc.getpwuid.name) @name = username warn "[DEPRECATION] `OSC::Machete::User` is deprecated. Please use `OodSupport::User` instead (see ood_support gem)." end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/osc/machete/user.rb', line 7 def name @name end |
Class Method Details
.from_uid(uid) ⇒ User
factory method to produce a User from specified uid
30 31 32 |
# File 'lib/osc/machete/user.rb', line 30 def self.from_uid(uid) self.new Etc.getpwuid(uid).name end |
Instance Method Details
#groups ⇒ Array
get sorted list of group ids that user is part of by inspecting the /etc/group file there is also a ruby impl of this
47 48 49 |
# File 'lib/osc/machete/user.rb', line 47 def groups `id -G $USER`.strip.split.map(&:to_i).uniq.sort end |
#home ⇒ String
The home directory path of the user.
72 73 74 |
# File 'lib/osc/machete/user.rb', line 72 def home Dir.home(@name) end |
#member_of_group?(group) ⇒ Boolean
Determine if user is member of specified group
38 39 40 |
# File 'lib/osc/machete/user.rb', line 38 def member_of_group?(group) Etc.getgrnam(group).mem.include?(@name) rescue false end |
#projects ⇒ Array<String>
get list of projects the user is part of FIXME: OSC specific
55 56 57 |
# File 'lib/osc/machete/user.rb', line 55 def projects `id -Gn`.split.grep(/^P./) end |