Class: GitoFigure

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

Constant Summary collapse

REPOS =
'/tmp/gitolites'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops = {}) ⇒ GitoFigure

Returns a new instance of GitoFigure.



6
7
8
# File 'lib/gitofigure.rb', line 6

def initialize(ops={})
  @repo = ops[:repo]
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



3
4
5
# File 'lib/gitofigure.rb', line 3

def repo
  @repo
end

Class Method Details

.administer(server, overrides = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitofigure.rb', line 10

def self.administer(server, overrides={})
  ops = {:git_user => 'gitolite', :repo => 'gitolite-admin', :server => server}.merge overrides
  upstream_url = ops[:git_user] + '@' + ops[:server] + ':' + ops[:repo]
  local_path = File.join(REPOS, ops[:server])
  git = GitoFigure.new

  git.repo = Dir.exists?(local_path) ? Git.open(local_path) : Git.clone(upstream_url, ops[:server], :path => REPOS)

  if block_given?
    git.repo.pull
    yield git
    git.repo.push
  else
    return git
  end
end

Instance Method Details

#authorize_keyfile(filename, msg = nil) ⇒ Object



35
36
37
38
39
40
# File 'lib/gitofigure.rb', line 35

def authorize_keyfile(filename, msg=nil)
  msg = ["Added #{File.basename(filename)}", msg].join("\n")
  FileUtils.mv(filename, repo.dir.to_s + '/keydir')
  repo.add 'keydir'
  repo.commit(msg)
end

#authorize_keys(hsh) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gitofigure.rb', line 27

def authorize_keys(hsh)
  hsh.each do |name, key|
    filename = File.join('/', 'tmp', name.to_s + '.pub')
    File.open(filename, "w") {|f| f.write(key.to_s)}
    authorize_keyfile(filename)
  end
end