Sha256: 726223ef2d9f974543d9f7b92c22d2eade1cabcda446e0b0f51562e285f52bbe

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 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 reset!
      @parser = nil
      @writer = nil
      @git = nil
      @repo_origin = nil
      @client = nil

      self
    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.5 lib/rubolite/admin.rb
rubolite-0.0.4 lib/rubolite/admin.rb