Class: Gitosis::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/gitosis_easy_conf/repositories.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Repository

Returns a new instance of Repository.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitosis_easy_conf/repositories.rb', line 11

def initialize(&block)
  @base_config = EmptyConfig

  conf_file_name = Gitosis.config.filename
  @no_file_found = if conf_file_name.nil? or !File.exists?(conf_file_name)
                     @conffile = {}
                     true
                   else
                     @conffile = IniFile.new(conf_file_name)
                     false
                   end
  @conffile["gitosis"] = {}
  @origconffile = @conffile.clone

  @fork_name = Gitosis.config.fork_naming_convention || lambda do |repo,forker|
    "#{forker}_#{repo}"
  end

  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gitosis_easy_conf/repositories.rb', line 42

def method_missing(method, *args, &block)
  args = [{}] if args.first.nil?
  repo_name = (args.first[:name] || method).to_sym

  committers = _get_keys([@base_config,args.first].map{|h| h[:writable]})
  @conffile["group #{repo_name}.writable"] = {
    'members'  => committers,
    'writable' => repo_name.to_s
  } unless committers == ""

  readers = _get_keys([@base_config,args.first].map{|h| h[:readable]})
  @conffile["group #{repo_name}.readonly"] = {
    'members'  => readers,
    'readonly' => repo_name.to_s
  } unless readers == ""

  [@base_config, args.first].map { |h| h[:forks] }.flatten.compact.
    collect { |a| a == :all ? Gitosis.forkers.all : a }.flatten.compact.each do |forker|

    fork_repo_name = @fork_name.call(repo_name,forker)

    @conffile["group fork.#{repo_name}.#{forker}.writable"] = {
      'members'  => ::Forker[forker],
      'writable' => fork_repo_name,
    }

    @conffile["group fork.#{repo_name}.#{forker}.readonly"] = {
      'members'  => readers,
      'readonly' => fork_repo_name,
    } unless readers == ""
  end
end

Instance Method Details

#with_base_configuration(config, &block) ⇒ Object



36
37
38
39
40
# File 'lib/gitosis_easy_conf/repositories.rb', line 36

def with_base_configuration(config,&block)
  @base_config = config || EmptyConfig
  instance_eval(&block)
  @base_config = EmptyConfig
end

#writeObject



32
33
34
# File 'lib/gitosis_easy_conf/repositories.rb', line 32

def write
  @conffile.write unless @conffile.eql?(@origconffile) || @no_file_found
end