class Licensee::GitProject
Constants
- MAX_LICENSE_SIZE
Attributes
repository[R]
revision[R]
Public Class Methods
new(repo, revision: nil, **args)
click to toggle source
Calls superclass method
Licensee::Project.new
# File lib/licensee/projects/git_project.rb, line 10 def initialize(repo, revision: nil, **args) @repository = if repo.is_a? Rugged::Repository repo else Rugged::Repository.new(repo) end @revision = revision super(**args) rescue Rugged::OSError, Rugged::RepositoryError raise InvalidRepository end
Public Instance Methods
close()
click to toggle source
# File lib/licensee/projects/git_project.rb, line 23 def close @repository.close end
Private Instance Methods
commit()
click to toggle source
# File lib/licensee/projects/git_project.rb, line 29 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 53 def files commit.tree.map do |entry| next unless entry[:type] == :blob { name: entry[:name], oid: entry[:oid] } 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 44 def load_file(file) data, = Rugged::Blob.to_buffer(repository, file[:oid], MAX_LICENSE_SIZE) data end