Class: Gitolite::Dtg::Config

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

Defined Under Namespace

Classes: Group, GroupDependencyError, ParseError, Repo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



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

def initialize(config)
  @special_groups = ["all","raven"]
  @repos = {}
  @groups = {}
  @flat_groups = {}
  @config_blob = config
  process_config(config)
  flatten_groups
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/gitolite-dtg/config.rb', line 220

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::Dtg::Config::Repo)
      when "group"
        normalize_name(args[0], Gitolite::Dtg::Config::Group)
    end
  else
    super
  end
end

Instance Attribute Details

#config_blobObject

Returns the value of attribute config_blob.



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

def config_blob
  @config_blob
end

#flat_groupsObject

Returns the value of attribute flat_groups.



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

def flat_groups
  @flat_groups
end

#groupsObject

Returns the value of attribute groups.



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

def groups
  @groups
end

#reposObject

Returns the value of attribute repos.



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

def repos
  @repos
end

#special_groupsObject

Returns the value of attribute special_groups.



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

def special_groups
  @special_groups
end

Instance Method Details

#add_group(group, overwrite = false) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
# File 'lib/gitolite-dtg/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)


21
22
23
24
# File 'lib/gitolite-dtg/config.rb', line 21

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-dtg/config.rb', line 60

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

#get_repo(repo) ⇒ Object



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

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

#get_repos(pattern) ⇒ Object



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

def get_repos(pattern)
  repos.keys.select {|k| k.include? pattern}
end

#has_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#has_repo?(repo) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/gitolite-dtg/config.rb', line 31

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-dtg/config.rb', line 50

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

#rm_repo(repo) ⇒ Object



26
27
28
29
# File 'lib/gitolite-dtg/config.rb', line 26

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
87
88
# File 'lib/gitolite-dtg/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.sort.each do |k, v|
      f.write "\n"
      f.write v.to_s

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

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

  new_conf
end