class Licensee::Projects::GitProject
Constants
- MAX_LICENSE_SIZE
Attributes
revision[R]
Public Class Methods
new(repo, revision: nil, **args)
click to toggle source
Calls superclass method
Licensee::Projects::Project::new
# File lib/licensee/projects/git_project.rb, line 20 def initialize(repo, revision: nil, **args) @raw_repo = repo @revision = revision raise InvalidRepository if repository.head_unborn? super(**args) end
Public Instance Methods
close()
click to toggle source
# File lib/licensee/projects/git_project.rb, line 39 def close repository.close end
repository()
click to toggle source
# File lib/licensee/projects/git_project.rb, line 29 def repository @repository ||= begin return @raw_repo if @raw_repo.is_a? Rugged::Repository Rugged::Repository.new(@raw_repo) end rescue Rugged::OSError, Rugged::RepositoryError raise InvalidRepository end
Private Instance Methods
commit()
click to toggle source
# File lib/licensee/projects/git_project.rb, line 45 def commit @commit ||= if revision repository.lookup(revision) else repository.last_commit end end
files()
click to toggle source
Returns an array of hashes representing the project’s files. Hashes will have the the following keys:
:name - the file's path relative to the repo root :oid - the file's OID
# File lib/licensee/projects/git_project.rb, line 69 def files @files ||= files_from_tree(commit.tree) end
files_from_tree(tree, dir = '.')
click to toggle source
# File lib/licensee/projects/git_project.rb, line 73 def files_from_tree(tree, dir = '.') tree.select { |e| e[:type] == :blob }.map do |entry| entry.merge(dir: dir) end.compact end
load_file(file)
click to toggle source
Retrieve a file’s content from the Git database
file - the file hash, including the file’s OID
Returns a string representing the file’s contents
# File lib/licensee/projects/git_project.rb, line 60 def load_file(file) data, = Rugged::Blob.to_buffer(repository, file[:oid], MAX_LICENSE_SIZE) data end