Class: TestForRoot::User

Inherits:
Object
  • Object
show all
Defined in:
lib/test_for_root/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUser

Returns a new instance of User.



6
7
8
9
10
# File 'lib/test_for_root/user.rb', line 6

def initialize
  @user = `id -un`.chomp
  @member_of = (`groups #{@user}`.chomp.split(":"))[1].split
  @user_id = %x{id -u}.chomp.to_i
end

Instance Attribute Details

#member_ofObject (readonly)

Returns the value of attribute member_of.



4
5
6
# File 'lib/test_for_root/user.rb', line 4

def member_of
  @member_of
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/test_for_root/user.rb', line 4

def user
  @user
end

#user_idObject (readonly)

Returns the value of attribute user_id.



4
5
6
# File 'lib/test_for_root/user.rb', line 4

def user_id
  @user_id
end

Instance Method Details

#groupsObject



16
17
18
# File 'lib/test_for_root/user.rb', line 16

def groups
  @member_of
end

#member?(group_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/test_for_root/user.rb', line 20

def member? (group_name)
  @member_of.include? group_name
end

#nameObject



12
13
14
# File 'lib/test_for_root/user.rb', line 12

def name
  @user
end

#uidObject



24
25
26
# File 'lib/test_for_root/user.rb', line 24

def uid
  @user_id
end