Class: UnixGroup
- Inherits:
-
Object
- Object
- UnixGroup
- Defined in:
- lib/unix_group.rb
Instance Attribute Summary collapse
-
#gid ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#name ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#password ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
-
#users ⇒ Object
readonly
——————————————————# Instance methods ——————————————————#.
Class Method Summary collapse
- .find(name) ⇒ Object
-
.list ⇒ Object
——————————————————# Static methods ——————————————————#.
Instance Method Summary collapse
-
#initialize(options) ⇒ UnixGroup
constructor
A new instance of UnixGroup.
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() @name = [:name] @password = [:password] @gid = [:gid].to_i @users = [:users] end |
Instance Attribute Details
#gid ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
35 36 37 |
# File 'lib/unix_group.rb', line 35 def gid @gid end |
#name ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
35 36 37 |
# File 'lib/unix_group.rb', line 35 def name @name end |
#password ⇒ Object (readonly)
——————————————————# Instance methods ——————————————————#
35 36 37 |
# File 'lib/unix_group.rb', line 35 def password @password end |
#users ⇒ Object (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 |
.list ⇒ Object
——————————————————# 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 |