Class: Gitolite::Config::Repo
- Inherits:
-
Object
- Object
- Gitolite::Config::Repo
- Defined in:
- lib/gitolite/config/repo.rb
Overview
Represents a repo inside the gitolite configuration. The name, permissions, and git config options are all encapsulated in this class
Defined Under Namespace
Classes: InvalidPermissionError
Constant Summary collapse
- ALLOWED_PERMISSIONS =
/-|C|R|RW\+?(?:C?D?|D?C?)M?/
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
Instance Method Summary collapse
- #add_permission(perm, refex = "", *users) ⇒ Object
- #clean_permissions ⇒ Object
- #gitweb_description ⇒ Object
-
#initialize(name) ⇒ Repo
constructor
A new instance of Repo.
- #set_git_config(key, value) ⇒ Object
- #to_s ⇒ Object
- #unset_git_config(key) ⇒ Object
Constructor Details
#initialize(name) ⇒ Repo
Returns a new instance of Repo.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gitolite/config/repo.rb', line 10 def initialize(name) #Store the perm hash in a lambda since we have to create a new one on every deny rule #The perm hash is stored as a 2D hash, with individual permissions being the first #degree and individual refexes being the second degree. Both Hashes must respect order @perm_hash_lambda = lambda { OrderedHash.new {|k,v| k[v] = OrderedHash.new{|k2, v2| k2[v2] = [] }} } @permissions = Array.new.push(@perm_hash_lambda.call) @name = name @config = {} #git config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/gitolite/config/repo.rb', line 8 def config @config end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/gitolite/config/repo.rb', line 8 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/gitolite/config/repo.rb', line 8 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
8 9 10 |
# File 'lib/gitolite/config/repo.rb', line 8 def owner @owner end |
#permissions ⇒ Object
Returns the value of attribute permissions.
8 9 10 |
# File 'lib/gitolite/config/repo.rb', line 8 def @permissions end |
Instance Method Details
#add_permission(perm, refex = "", *users) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitolite/config/repo.rb', line 25 def (perm, refex = "", *users) if perm =~ ALLOWED_PERMISSIONS #Handle deny rules if perm == '-' @permissions.push(@perm_hash_lambda.call) end @permissions.last[perm][refex].concat users.flatten @permissions.last[perm][refex].uniq! else raise InvalidPermissionError, "#{perm} is not in the allowed list of permissions!" end end |
#clean_permissions ⇒ Object
21 22 23 |
# File 'lib/gitolite/config/repo.rb', line 21 def @permissions = Array.new.push(@perm_hash_lambda.call) end |
#gitweb_description ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/gitolite/config/repo.rb', line 65 def gitweb_description if @description.nil? nil else desc = "#{@name} " desc += "\"#{@owner}\" " unless @owner.nil? desc += "= \"#{@description}\"" end end |
#set_git_config(key, value) ⇒ Object
39 40 41 |
# File 'lib/gitolite/config/repo.rb', line 39 def set_git_config(key, value) @config[key] = value end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitolite/config/repo.rb', line 47 def to_s repo = "repo #{@name}\n" @permissions.each do |perm_hash| perm_hash.each do |perm, list| list.each do |refex, users| repo += " " + perm.ljust(6) + refex.ljust(25) + "= " + users.join(' ') + "\n" end end end @config.each do |k, v| repo += " config " + k + " = " + v + "\n" end repo end |
#unset_git_config(key) ⇒ Object
43 44 45 |
# File 'lib/gitolite/config/repo.rb', line 43 def unset_git_config(key) @config.delete(key) end |