Class: UnixGroup

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ UnixGroup

Returns a new instance of UnixGroup.



40
41
42
43
44
45
# File 'lib/unix_group.rb', line 40

def initialize(options)
  @name = options[:name]
  @password = options[:password]
  @gid = options[:gid].to_i
  @users = options[:users]
end

Instance Attribute Details

#gidObject (readonly)

——————————————————# Instance methods ——————————————————#



35
36
37
# File 'lib/unix_group.rb', line 35

def gid
  @gid
end

#nameObject (readonly)

——————————————————# Instance methods ——————————————————#



35
36
37
# File 'lib/unix_group.rb', line 35

def name
  @name
end

#passwordObject (readonly)

——————————————————# Instance methods ——————————————————#



35
36
37
# File 'lib/unix_group.rb', line 35

def password
  @password
end

#usersObject (readonly)

——————————————————# Instance methods ——————————————————#



35
36
37
# File 'lib/unix_group.rb', line 35

def users
  @users
end

Class Method Details

.find(name) ⇒ Object



26
27
28
29
# File 'lib/unix_group.rb', line 26

def self.find(name)
  groups = list.select { |group| group.name == name }
  groups.size != 0 ? groups.first : nil
end

.listObject

——————————————————# Static methods ——————————————————#



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/unix_group.rb', line 9

def self.list
  passwd_file = File.open('/etc/group', 'r')
  passwd_data = passwd_file.read
  entries = passwd_data.split "\n"
  list = []
  entries.each do |entry|
    fields = entry.split(':')
    list << UnixGroup.new({
                              :name => fields[0],
                              :password => fields[1],
                              :gid => fields[2],
                              :users => fields[3]
                          })
  end
  list
end