Sha256: b0517ba2fe696f73d78324f8f10fc90683316f31d0e99e5fb6c88c0693fc9446

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require "git"

module Rubolite
  class Admin
    InvalidPath = Class.new(Exception)
    InvalidGitRepo = Class.new(Exception)
    InvalidRepo = Class.new(Exception)

    attr_reader :path, :repos

    def initialize(path=nil)
      @path = path if path && valid_path?(path)
    end

    def path=(new_path)
      valid_path?(new_path)
      @path = new_path
    end

    def add_repo(repo)
      raise InvalidRepo, "Repo not type of Rubolite::Repo, got #{repo.class}" unless repo.kind_of?(Repo)
      (@repos ||= []) << repo
    end
    alias :<< :add_repo

    def parser
      @parser ||= Parser.new("#{path}/conf/gitolite.conf")
    end

    def writer
      @writer ||= parser.writer
    end

    def git
      @git ||= Git.open(path)
    end

    def repo_origin
      @repo_origin ||= git.remote("origin")
    end

    def client
      @client ||= Client.new(self)
    end

    private

    def valid_path?(path)
      raise InvalidPath, "#{path} is not a directory" unless File.directory?(path)
      raise InvalidGitRepo, "#{path} is not a git repository" unless File.directory?("#{path}/.git")
      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubolite-0.0.3 lib/rubolite/admin.rb
rubolite-0.0.2 lib/rubolite/admin.rb