Class: Bake::Modernize::License::Contributors
- Inherits:
-
Object
- Object
- Bake::Modernize::License::Contributors
- Defined in:
- lib/bake/modernize/license.rb
Overview
Extract contributors from a YAML file which can be generated from another repository.
Constant Summary collapse
- 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.
"."
Instance Attribute Summary collapse
-
#contributions ⇒ Object
readonly
Returns the value of attribute contributions.
- #The list of contributions.(listofcontributions.) ⇒ Object readonly
- #The list of paths from a given contribution.(listofpathsfromagivencontribution.) ⇒ Object readonly
Class Method Summary collapse
-
.for(root, mailmap: nil) ⇒ Object
Load contributors from a directory.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterate over each contribution.
-
#extract(path) ⇒ Object
Extract the contributors from the given path.
-
#initialize(mailmap: nil) ⇒ Contributors
constructor
Create a new, empty, contributors list.
- #paths_for(contribution) ⇒ Object
Constructor Details
#initialize(mailmap: nil) ⇒ Contributors
Create a new, empty, contributors list.
124 125 126 127 |
# File 'lib/bake/modernize/license.rb', line 124 def initialize(mailmap: nil) @contributions = [] @mailmap = mailmap end |
Instance Attribute Details
#contributions ⇒ Object (readonly)
Returns the value of attribute contributions.
130 131 132 |
# File 'lib/bake/modernize/license.rb', line 130 def contributions @contributions end |
#The list of contributions.(listofcontributions.) ⇒ Object (readonly)
130 |
# File 'lib/bake/modernize/license.rb', line 130 attr :contributions |
#The list of paths from a given contribution.(listofpathsfromagivencontribution.) ⇒ Object (readonly)
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/bake/modernize/license.rb', line 157 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 |
Class Method Details
.for(root, mailmap: nil) ⇒ Object
Load contributors from a directory.
113 114 115 116 117 118 119 120 121 |
# File 'lib/bake/modernize/license.rb', line 113 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 |
Instance Method Details
#each(&block) ⇒ Object
Iterate over each contribution.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/bake/modernize/license.rb', line 133 def each(&block) @contributions.each do |contribution| = contribution[:author].dup time = contribution[:time] # Apply mailmap transformation if available if @mailmap && [:email] && mapped_name = @mailmap.names[[:email]] [:name] = mapped_name end paths_for(contribution) do |path| yield path, , time end end end |
#extract(path) ⇒ Object
Extract the contributors from the given path.
150 151 152 153 154 |
# File 'lib/bake/modernize/license.rb', line 150 def extract(path) @contributions.concat( YAML.load_file(path, aliases: true, symbolize_names: true, permitted_classes: [Symbol, Date, Time]) ) end |
#paths_for(contribution) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/bake/modernize/license.rb', line 157 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 |