Class: Gitolite::Config

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

Defined Under Namespace

Classes: Group, GroupDependencyError, ParseError, Repo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.


9
10
11
12
13
14
# File 'lib/gitolite/config.rb', line 9

def initialize(config)
  @repos = {}
  @groups = {}
  @filename = File.basename(config)
  process_config(config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/gitolite/config.rb', line 191

def method_missing(meth, *args, &block)
  if meth.to_s =~ /normalize_(\w+)_name/
    #Could use Object.const_get to figure out the constant here
    #but for only two cases, this is more readable
    case $1
      when "repo"
        normalize_name(args[0], Gitolite::Config::Repo)
      when "group"
        normalize_name(args[0], Gitolite::Config::Group)
    end
  else
    super
  end
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename


7
8
9
# File 'lib/gitolite/config.rb', line 7

def filename
  @filename
end

#groupsObject

Returns the value of attribute groups


7
8
9
# File 'lib/gitolite/config.rb', line 7

def groups
  @groups
end

#reposObject

Returns the value of attribute repos


7
8
9
# File 'lib/gitolite/config.rb', line 7

def repos
  @repos
end

Class Method Details

.init(filename = "gitolite.conf") ⇒ Object


16
17
18
19
20
21
22
# File 'lib/gitolite/config.rb', line 16

def self.init(filename = "gitolite.conf")
  file = Tempfile.new(filename)
  conf = self.new(file.path)
  conf.filename = filename #kill suffix added by Tempfile
  file.close(unlink_now = true)
  conf
end

Instance Method Details

#add_group(group, overwrite = false) ⇒ Object

Raises:

  • (ArgumentError)

45
46
47
48
# File 'lib/gitolite/config.rb', line 45

def add_group(group, overwrite = false)
  raise ArgumentError, "Group must be of type Gitolite::Config::Group!" unless group.instance_of? Gitolite::Config::Group
  @groups[group.name] = group
end

#add_repo(repo, overwrite = false) ⇒ Object

TODO: merge repo unless overwrite = true

Raises:

  • (ArgumentError)

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

def add_repo(repo, overwrite = false)
  raise ArgumentError, "Repo must be of type Gitolite::Config::Repo!" unless repo.instance_of? Gitolite::Config::Repo
  @repos[repo.name] = repo
end

#get_group(group) ⇒ Object


60
61
62
63
# File 'lib/gitolite/config.rb', line 60

def get_group(group)
  name = normalize_group_name(group)
  @groups[name]
end

#get_repo(repo) ⇒ Object


40
41
42
43
# File 'lib/gitolite/config.rb', line 40

def get_repo(repo)
  name = normalize_repo_name(repo)
  @repos[name]
end

#has_group?(group) ⇒ Boolean

Returns:

  • (Boolean)

55
56
57
58
# File 'lib/gitolite/config.rb', line 55

def has_group?(group)
  name = normalize_group_name(group)
  @groups.has_key?(name)
end

#has_repo?(repo) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
38
# File 'lib/gitolite/config.rb', line 35

def has_repo?(repo)
  name = normalize_repo_name(repo)
  @repos.has_key?(name)
end

#rm_group(group) ⇒ Object


50
51
52
53
# File 'lib/gitolite/config.rb', line 50

def rm_group(group)
  name = normalize_group_name(group)
  @groups.delete(name)
end

#rm_repo(repo) ⇒ Object


30
31
32
33
# File 'lib/gitolite/config.rb', line 30

def rm_repo(repo)
  name = normalize_repo_name(repo)
  @repos.delete(name)
end

#to_file(path = ".", filename = @filename) ⇒ Object

Raises:

  • (ArgumentError)

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gitolite/config.rb', line 65

def to_file(path=".", filename=@filename)
  raise ArgumentError, "Path contains a filename or does not exist" unless File.directory?(path)

  new_conf = File.join(path, filename)
  File.open(new_conf, "w") do |f|
    #Output groups
    dep_order = build_groups_depgraph
    dep_order.each {|group| f.write group.to_s }

    gitweb_descs = []
    @repos.each do |k, v|
      f.write v.to_s

      gwd = v.gitweb_description
      gitweb_descs.push(gwd) unless gwd.nil?
    end

    f.write gitweb_descs.join("\n")
  end

  new_conf
end