From 9e1814a10c0e5708727389e87d257b97aa7760af Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Thu, 10 Mar 2011 15:38:42 +0300 Subject: [PATCH] simple git repository class for the project --- app/models/git/repository.rb | 28 ++++++++++++++++++++++++++++ app/models/project.rb | 2 ++ app/models/project/has_repository.rb | 14 ++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 app/models/git/repository.rb create mode 100644 app/models/project/has_repository.rb diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb new file mode 100644 index 000000000..0ee2fdfd6 --- /dev/null +++ b/app/models/git/repository.rb @@ -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 \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 4f80ba256..43a42232f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -7,6 +7,8 @@ class Project < ActiveRecord::Base before_validation :generate_unixname + include Project::HasRepository + protected def generate_unixname diff --git a/app/models/project/has_repository.rb b/app/models/project/has_repository.rb new file mode 100644 index 000000000..a109297a2 --- /dev/null +++ b/app/models/project/has_repository.rb @@ -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 \ No newline at end of file