Class: UnixUserManager::Users

Inherits:
Base
  • Object
show all
Defined in:
lib/unix_user_manager/users.rb

Constant Summary

Constants inherited from Base

Base::DELEGATED_METHODS

Instance Attribute Summary collapse

Attributes inherited from Base

#file

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(passwd:, shadow:) ⇒ Users

Returns a new instance of Users.



4
5
6
7
# File 'lib/unix_user_manager/users.rb', line 4

def initialize(passwd:, shadow:)
  @file = passwd
  @shadow_file = shadow
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UnixUserManager::Base

Instance Attribute Details

#shadow_fileObject (readonly)

Returns the value of attribute shadow_file.



2
3
4
# File 'lib/unix_user_manager/users.rb', line 2

def shadow_file
  @shadow_file
end

Instance Method Details

#add(name:, uid:, gid:) ⇒ Object



33
34
35
36
37
# File 'lib/unix_user_manager/users.rb', line 33

def add(name:, uid:, gid:)
  return false unless file.can_add?(name, uid) && shadow_file.can_add?(name)

  file.add(name: name, uid: uid, gid: gid) && shadow_file.add(name: name)
end

#buildObject



25
26
27
# File 'lib/unix_user_manager/users.rb', line 25

def build
  { passwd: build_passwd, shadow: build_shadow }
end

#build_new_recordsObject



29
30
31
# File 'lib/unix_user_manager/users.rb', line 29

def build_new_records
  { passwd: build_passwd_new_records, shadow: build_shadow_new_records }
end

#build_passwdObject



9
10
11
# File 'lib/unix_user_manager/users.rb', line 9

def build_passwd
  file.build
end

#build_passwd_new_recordsObject



13
14
15
# File 'lib/unix_user_manager/users.rb', line 13

def build_passwd_new_records
  file.build_new_records
end

#build_shadowObject



17
18
19
# File 'lib/unix_user_manager/users.rb', line 17

def build_shadow
  shadow_file.build
end

#build_shadow_new_recordsObject



21
22
23
# File 'lib/unix_user_manager/users.rb', line 21

def build_shadow_new_records
  shadow_file.build_new_records
end