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