Class: Gitolite::Config::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/gitolite/config/group.rb

Overview

Represents a group inside the gitolite configuration. The name and users options are all encapsulated in this class. All users are stored as Strings!

Constant Summary collapse

PREPEND_CHAR =
'@'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Group

Returns a new instance of Group.


13
14
15
16
17
18
# File 'lib/gitolite/config/group.rb', line 13

def initialize(name)
  # naively remove the prepend char
  # I don't think you can have two of them in a group name
  @name = name.gsub(PREPEND_CHAR, '')
  @users = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


9
10
11
# File 'lib/gitolite/config/group.rb', line 9

def name
  @name
end

#usersObject

Returns the value of attribute users


9
10
11
# File 'lib/gitolite/config/group.rb', line 9

def users
  @users
end

Instance Method Details

#add_user(user) ⇒ Object


26
27
28
29
# File 'lib/gitolite/config/group.rb', line 26

def add_user(user)
  return if has_user?(user)
  @users.push(user.to_s).sort!
end

#add_users(*users) ⇒ Object


32
33
34
35
# File 'lib/gitolite/config/group.rb', line 32

def add_users(*users)
  fixed_users = users.flatten.map{ |u| u.to_s }
  @users.concat(fixed_users).sort!.uniq!
end

#empty!Object


21
22
23
# File 'lib/gitolite/config/group.rb', line 21

def empty!
  @users.clear
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/gitolite/config/group.rb', line 43

def has_user?(user)
  @users.include? user.to_s
end

#rm_user(user) ⇒ Object


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

def rm_user(user)
  @users.delete(user.to_s)
end

#sizeObject


48
49
50
# File 'lib/gitolite/config/group.rb', line 48

def size
  @users.length
end

#to_sObject


53
54
55
56
57
# File 'lib/gitolite/config/group.rb', line 53

def to_s
  members = @users.join(' ')
  name = "#{PREPEND_CHAR}#{@name}"
  "#{name.ljust(20)}= #{members}\n"
end