Class: Gitolite::Dtg::Config::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/gitolite-dtg/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.



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

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.



8
9
10
# File 'lib/gitolite-dtg/config/group.rb', line 8

def name
  @name
end

#usersObject

Returns the value of attribute users.



8
9
10
# File 'lib/gitolite-dtg/config/group.rb', line 8

def users
  @users
end

Instance Method Details

#add_user(user) ⇒ Object



23
24
25
26
# File 'lib/gitolite-dtg/config/group.rb', line 23

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

#add_users(*users) ⇒ Object



28
29
30
31
# File 'lib/gitolite-dtg/config/group.rb', line 28

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

#empty!Object



19
20
21
# File 'lib/gitolite-dtg/config/group.rb', line 19

def empty!
  @users.clear
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/gitolite-dtg/config/group.rb', line 37

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

#rm_user(user) ⇒ Object



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

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

#sizeObject



41
42
43
# File 'lib/gitolite-dtg/config/group.rb', line 41

def size
  @users.length
end

#to_sObject



45
46
47
48
49
# File 'lib/gitolite-dtg/config/group.rb', line 45

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