class Contributors
Extract contributors from a YAML file which can be generated from another repository.
Definitions
DEFAULT_PATH = "."
The default path is the root of the repository and for authors who have contributed to the entire repository or unspecified paths in the past.
def self.for(root)
Load contributors from a directory.
Implementation
def self.for(root)
full_path = File.join(root, ".contributors.yaml")
if File.exist?(full_path)
contributors = self.new
contributors.extract(full_path)
return contributors
end
end
def initialize
Create a new, empty, contributors list.
Implementation
def initialize
@contributions = []
end
def each(&block)
Iterate over each contribution.
Implementation
def each(&block)
@contributions.each do |contribution|
author = contribution[:author]
time = contribution[:time]
paths_for(contribution) do |path|
yield path, author, time
end
end
end
def extract(path)
Extract the contributors from the given path.
Implementation
def extract(path)
@contributions.concat(
YAML.load_file(path, aliases: true, symbolize_names: true, permitted_classes: [Symbol, Date, Time])
)
end
def paths_for(contribution)
Signature
-
attribute
Array(Hash)
The list of paths from a given contribution.
Implementation
def paths_for(contribution)
return to_enum(:paths_for, contribution) unless block_given?
if path = contribution[:path]
yield path
# elsif paths = contribution[:paths]
# paths.each do |path|
# yield path
# end
else
yield DEFAULT_PATH
end
end