class RBT::Users

Public Class Methods

new( shall_we_report = false ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/users.rb, line 20
def initialize(
    shall_we_report = false
  )
  reset
  unless is_on_windows? # skip this if we are on windows
    Etc.passwd { |user|         # user id, group id
      @passwd_info[user.name] = [ user.uid, user.gid ]
      @superuser_name = user.name if user.uid == 0
    }
  end
  report if shall_we_report
end

Public Instance Methods

fetch_user(name) click to toggle source
#

fetch_user

This method will specifically fetch a user.

#
# File lib/rbt/utility_scripts/users.rb, line 65
def fetch_user(name)
  @passwd_info[name] if @passwd_info.keys.include? name
end
passwd_info()
Alias for: passwd_info?
passwd_info?() click to toggle source
#

passwd_info?

#
# File lib/rbt/utility_scripts/users.rb, line 47
def passwd_info?
  @passwd_info
end
Also aliased as: passwd_info
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/users.rb, line 36
def reset
  super()
  # ======================================================================= #
  # === @passwd_info
  # ======================================================================= #
  @passwd_info = {}
end
superuser_name?() click to toggle source
#

superuser_name?

This method will simply return the name of the superuser.

#
# File lib/rbt/utility_scripts/users.rb, line 56
def superuser_name?
  @superuser_name
end

Private Instance Methods

report() click to toggle source
#

report

We will report with some useful information to the user.

#
# File lib/rbt/utility_scripts/users.rb, line 74
def report
  cliner {
    opn; e "Available Users ("\
           "#{simp(@passwd_info.keys.size.to_s)} in total):"
  }
  sort_by_uid = @passwd_info.sort_by {|key, value|
    uid = value[0]
    uid
  } 
  e; sort_by_uid.each { |entry|
    user_name = entry.first
    uid = entry[1][0].to_s
    gid = entry[1][1].to_s
    e '  User: '+Colours.yellow(user_name.ljust(10))+
       sfancy('   UID: '+uid.to_s.rjust(4)+' GID: '+gid.to_s.rjust(4))
  }; e
end