class Authorship
Represents the authorship of a repository.
Nested
Definitions
def initialize
Create a new, empty, authorship.
Implementation
def initialize
@paths = Hash.new{|h,k| h[k] = []}
@commits = Hash.new{|h,k| h[k] = []}
end
attr :paths
Signature
-
attribute
Hash(String, Array(Modification)) The mapping of paths to modifications.
attr :commits
Signature
-
attribute
Hash(String, Array(Modification)) The mapping of commits to modifications.
def add(path, author, time, id = nil)
Add a modification to the authorship.
Implementation
def add(path, author, time, id = nil)
modification = Modification.new(author, time, path, id)
@commits[modification.key] << modification
@paths[path] << modification
end
def extract(root = Dir.pwd)
Extract the authorship from the given root directory.
Implementation
def extract(root = Dir.pwd)
mailmap = Mailmap.for(root)
skip_list = SkipList.for(root)
if contributors = Contributors.for(root, mailmap: mailmap)
contributors.each do |path, author, time|
add(path, author, time)
end
end
walk(Rugged::Repository.discover(root), mailmap: mailmap, skip_list: skip_list)
return self
end
def copyrights
All copyrights.
Implementation
def copyrights
copyrights_for_modifications(@paths.values.flatten)
end
def copyrights_for_path(path)
All copyrights for a given path.
Implementation
def copyrights_for_path(path)
copyrights_for_modifications(@paths[path])
end
def copyrights_for_modifications(modifications)
All copyrights for a given modification.
Implementation
def copyrights_for_modifications(modifications)
authors = modifications.group_by{|modification| modification.full_name}
authors.map do |name, modifications|
Copyright.new(modifications.map(&:time).minmax, name)
end.sort
end