simple git repository class for the project

This commit is contained in:
Timothy N. Tsvetkov 2011-03-10 15:38:42 +03:00
parent de2dc18249
commit 9e1814a10c
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,28 @@
class Git::Repository
delegate :commits, :tree, :to => :repo
attr_accessor :path, :name
def initialize(path, name)
@path = path
@name = name
end
def master
commits.first
end
def to_s
name
end
def repo
@repo ||= Grit::Repo.new(repo_path)
end
protected
def repo_path
@repo_path ||= File.join(path, name)
end
end

View File

@ -7,6 +7,8 @@ class Project < ActiveRecord::Base
before_validation :generate_unixname
include Project::HasRepository
protected
def generate_unixname

View File

@ -0,0 +1,14 @@
module Project::HasRepository
def self.included(model)
end
def git_repository
@repository ||= Git::Repository(git_repo_path, name)
end
protected
def git_repo_path
@git_repo_path ||= "xxx"
end
end