Class: UnixUser
- Inherits:
-
Object
- Object
- UnixUser
- Defined in:
- lib/unix_user.rb
Instance Attribute Summary collapse
-
#gid ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#home_directory ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#password ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#shell ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#uid ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#user_info ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#username ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
Class Method Summary collapse
- .find(username) ⇒ Object
-
.list ⇒ Object
——————————————————# Static methods ——————————————————#.
Instance Method Summary collapse
-
#initialize(options) ⇒ UnixUser
constructor
A new instance of UnixUser.
- #locked? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ UnixUser
Returns a new instance of UnixUser.
46 47 48 49 50 51 52 53 54 |
# File 'lib/unix_user.rb', line 46 def initialize() @username = [:username] @password = [:password] @uid = [:uid].to_i @gid = [:gid].to_i @user_info = [:user_info] @home_directory = [:home_directory] @shell = [:shell] end |
Instance Attribute Details
#gid ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def gid @gid end |
#home_directory ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def home_directory @home_directory end |
#password ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def password @password end |
#shell ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def shell @shell end |
#uid ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def uid @uid end |
#user_info ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def user_info @user_info end |
#username ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
38 39 40 |
# File 'lib/unix_user.rb', line 38 def username @username end |
Class Method Details
.find(username) ⇒ Object
29 30 31 32 |
# File 'lib/unix_user.rb', line 29 def self.find(username) users = list.select { |user| user.username == username } users.size != 0 ? users.first : nil end |
.list ⇒ Object
——————————————————# Static methods ——————————————————#
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/unix_user.rb', line 9 def self.list passwd_file = File.open('/etc/passwd', 'r') passwd_data = passwd_file.read entries = passwd_data.split "\n" list = [] entries.each do |entry| fields = entry.split(':') list << UnixUser.new({ :username => fields[0], :password => fields[1], :uid => fields[2], :gid => fields[3], :user_info => fields[4], :home_directory => fields[5], :shell => fields[6] }) end list end |
Instance Method Details
#locked? ⇒ Boolean
56 57 58 59 |
# File 'lib/unix_user.rb', line 56 def locked? m = /^.*?\s(.)/.match(status) m[1] == 'L' end |