Class: OodSupport::Group

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ood_support/group.rb

Overview

A helper object describing a Unix group's details

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group = Process.group) ⇒ Group


17
18
19
20
21
22
23
24
25
# File 'lib/ood_support/group.rb', line 17

def initialize(group = Process.group)
  if group.is_a?(Fixnum)
    @id = group
    @name = Etc.getgrgid(@id).name
  else
    @name = group.to_s
    @id = Etc.getgrnam(@name).gid
  end
end

Instance Attribute Details

#idFixnum (readonly)

The id of the group


10
11
12
# File 'lib/ood_support/group.rb', line 10

def id
  @id
end

#nameString (readonly)

The name of the group


14
15
16
# File 'lib/ood_support/group.rb', line 14

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Fixnum

The comparison operator for sorting values


30
31
32
# File 'lib/ood_support/group.rb', line 30

def <=>(other)
  name <=> other
end

#eql?(other) ⇒ Boolean

Checks whether two Group objects have the same group as well as that the object is in the Group class


38
39
40
# File 'lib/ood_support/group.rb', line 38

def eql?(other)
  self.class == other.class && self == other
end

#hashFixnum

Generates a hash value for this object


44
45
46
# File 'lib/ood_support/group.rb', line 44

def hash
  [self.class, name].hash
end

#to_sString

Convert object to string using group name as string value


50
51
52
# File 'lib/ood_support/group.rb', line 50

def to_s
  name
end