lib/gitolite/config.rb in gitolite-0.0.1.alpha vs lib/gitolite/config.rb in gitolite-0.0.2.alpha

- old
+ new

@@ -1,12 +1,13 @@ module Gitolite class Config - attr_accessor :repos, :groups + attr_accessor :repos, :groups, :filename def initialize(config) @repos = {} @groups = Hash.new { |k,v| k[v] = [] } + @filename = File.basename(config) process_config(config) end #Represents a repo inside the gitolite configuration. The name, permissions, and git config #options are all encapsulated in this class @@ -19,11 +20,11 @@ @name = name @permissions = Hash.new {|k,v| k[v] = Hash.new{|k2, v2| k2[v2] = [] }} @config = {} end - def add_permission(perm, refex, users) + def add_permission(perm, refex, *users) if ALLOWED_PERMISSIONS.include? perm @permissions[perm][refex].concat users else raise InvalidPermissionError, "#{perm} is not in the allowed list of permissions!" end @@ -36,19 +37,54 @@ def unset_git_config(key) @config.delete(key) end def to_s - @name + repo = "repo #{@name}\n" + + @permissions.each do |perm, list| + list.each do |refex, users| + repo += " " + perm.ljust(6) + refex.ljust(20) + "= " + users.join(' ') + "\n" + end + end + + repo end #Gets raised if a permission that isn't in the allowed #list is passed in class InvalidPermissionError < RuntimeError end end + #TODO: merge repo unless overwrite = true + def add_repo(repo, overwrite = false) + raise "Repo must be of type Gitolite::Config::Repo!" unless repo.instance_of? Gitolite::Config::Repo + @repos[repo.name] = repo + end + + def rm_repo(repo) + raise "Repo must be of type Gitolite::Config::Repo!" unless repo.instance_of? Gitolite::Config::Repo + @repos.delete repo.name + end + + def to_file(path) + new_conf = File.join(path, @filename) + File.open(new_conf, "w") do |f| + @groups.each do |k,v| + members = v.join(' ') + f.write "#{k.ljust(20)}= #{members}\n" + end + + @repos.each do |k, v| + f.write v.to_s + end + end + + new_conf + end + private #Based on #https://github.com/sitaramc/gitolite/blob/pu/src/gl-compile-conf#cleanup_conf_line def cleanup_config_line(line) #remove comments, even those that happen inline @@ -114,10 +150,8 @@ else puts "The following line cannot be processed:" puts "'#{line}'" end end - - end end -end \ No newline at end of file +end