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

Returns a new instance of Group.

Parameters:

  • group (Fixnum, #to_s) (defaults to: Process.group)

    the group id or name


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

Returns:

  • (Fixnum)

    the group id


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

def id
  @id
end

#nameString (readonly)

The name of the group

Returns:

  • (String)

    the group name


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

Parameters:

  • other (#to_s)

    group to compare against

Returns:

  • (Fixnum)

    how groups compare


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

Parameters:

  • other (Group)

    group to compare against

Returns:

  • (Boolean)

    whether same objects


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

Returns:

  • (Fixnum)

    hash value of 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

Returns:

  • (String)

    the group name


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

def to_s
  name
end