class Bake::Modernize::License::Contributors
Extract contributors from a YAML file which can be generated from another repository.
def self.for(root, mailmap: nil)
def self.for(root, mailmap: nil) full_path = File.join(root, ".contributors.yaml") if File.exist?(full_path) contributors = self.new(mailmap: mailmap) contributors.extract(full_path) return contributors end end
def each(&block)
def each(&block) @contributions.each do |contribution| author = contribution[:author].dup time = contribution[:time] # Apply mailmap transformation if available if @mailmap && author[:email] && mapped_name = @mailmap.names[author[:email]] author[:name] = mapped_name end paths_for(contribution) do |path| yield path, author, time end end end
def extract(path)
def extract(path) @contributions.concat( YAML.load_file(path, aliases: true, symbolize_names: true, permitted_classes: [Symbol, Date, Time]) ) end
def initialize(mailmap: nil)
def initialize(mailmap: nil) @contributions = [] @mailmap = mailmap end
def paths_for(contribution)
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