Class: Gitolite::Config::Group
- Inherits:
-
Object
- Object
- Gitolite::Config::Group
- 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
-
#name ⇒ Object
Returns the value of attribute name.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
- #add_user(user) ⇒ Object
- #add_users(*users) ⇒ Object
- #empty! ⇒ Object
- #has_user?(user) ⇒ Boolean
-
#initialize(name) ⇒ Group
constructor
A new instance of Group.
- #rm_user(user) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Group
Returns a new instance of Group.
11 12 13 14 15 16 |
# File 'lib/gitolite/config/group.rb', line 11 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
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/gitolite/config/group.rb', line 7 def name @name end |
#users ⇒ Object
Returns the value of attribute users.
7 8 9 |
# File 'lib/gitolite/config/group.rb', line 7 def users @users end |
Instance Method Details
#add_user(user) ⇒ Object
22 23 24 25 |
# File 'lib/gitolite/config/group.rb', line 22 def add_user(user) return if has_user?(user) @users.push(user.to_s).sort! end |
#add_users(*users) ⇒ Object
27 28 29 30 |
# File 'lib/gitolite/config/group.rb', line 27 def add_users(*users) fixed_users = users.flatten.map{ |u| u.to_s } @users.concat(fixed_users).sort!.uniq! end |
#empty! ⇒ Object
18 19 20 |
# File 'lib/gitolite/config/group.rb', line 18 def empty! @users.clear end |
#has_user?(user) ⇒ Boolean
36 37 38 |
# File 'lib/gitolite/config/group.rb', line 36 def has_user?(user) @users.include? user.to_s end |
#rm_user(user) ⇒ Object
32 33 34 |
# File 'lib/gitolite/config/group.rb', line 32 def rm_user(user) @users.delete(user.to_s) end |
#size ⇒ Object
40 41 42 |
# File 'lib/gitolite/config/group.rb', line 40 def size @users.length end |
#to_s ⇒ Object
44 45 46 47 48 |
# File 'lib/gitolite/config/group.rb', line 44 def to_s members = @users.join(' ') name = "#{PREPEND_CHAR}#{@name}" "#{name.ljust(20)}= #{members}\n" end |