Class: Bake::Modernize::License::Authorship
- Inherits:
-
Object
- Object
- Bake::Modernize::License::Authorship
- Defined in:
- lib/bake/modernize/license.rb
Overview
Represents the authorship of a repository.
Defined Under Namespace
Classes: Copyright, Modification
Instance Attribute Summary collapse
-
#commits ⇒ Object
readonly
Returns the value of attribute commits.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
- #The mapping of commits to modifications.(mappingofcommitstomodifications.) ⇒ Object readonly
- #The mapping of paths to modifications.(mappingofpathstomodifications.) ⇒ Object readonly
Instance Method Summary collapse
-
#add(path, author, time, id = nil) ⇒ Object
Add a modification to the authorship.
-
#copyrights ⇒ Object
All copyrights.
-
#copyrights_for_modifications(modifications) ⇒ Object
All copyrights for a given modification.
-
#copyrights_for_path(path) ⇒ Object
All copyrights for a given path.
-
#extract(root = Dir.pwd) ⇒ Object
Extract the authorship from the given root directory.
-
#initialize ⇒ Authorship
constructor
Create a new, empty, authorship.
-
#sorted_authors ⇒ Object
Authors, sorted by contribution date.
Constructor Details
#initialize ⇒ Authorship
Create a new, empty, authorship.
208 209 210 211 |
# File 'lib/bake/modernize/license.rb', line 208 def initialize @paths = Hash.new{|h,k| h[k] = []} @commits = Hash.new{|h,k| h[k] = []} end |
Instance Attribute Details
#commits ⇒ Object (readonly)
Returns the value of attribute commits.
217 218 219 |
# File 'lib/bake/modernize/license.rb', line 217 def commits @commits end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
214 215 216 |
# File 'lib/bake/modernize/license.rb', line 214 def paths @paths end |
#The mapping of commits to modifications.(mappingofcommitstomodifications.) ⇒ Object (readonly)
217 |
# File 'lib/bake/modernize/license.rb', line 217 attr :commits |
#The mapping of paths to modifications.(mappingofpathstomodifications.) ⇒ Object (readonly)
214 |
# File 'lib/bake/modernize/license.rb', line 214 attr :paths |
Instance Method Details
#add(path, author, time, id = nil) ⇒ Object
Add a modification to the authorship.
220 221 222 223 224 225 |
# File 'lib/bake/modernize/license.rb', line 220 def add(path, , time, id = nil) modification = Modification.new(, time, path, id) @commits[modification.key] << modification @paths[path] << modification end |
#copyrights ⇒ Object
All copyrights.
257 258 259 |
# File 'lib/bake/modernize/license.rb', line 257 def copyrights copyrights_for_modifications(@paths.values.flatten) end |
#copyrights_for_modifications(modifications) ⇒ Object
All copyrights for a given modification.
267 268 269 270 271 272 273 |
# File 'lib/bake/modernize/license.rb', line 267 def copyrights_for_modifications(modifications) = modifications.group_by{|modification| modification.full_name} .map do |name, modifications| Copyright.new(modifications.map(&:time).minmax, name) end.sort end |
#copyrights_for_path(path) ⇒ Object
All copyrights for a given path.
262 263 264 |
# File 'lib/bake/modernize/license.rb', line 262 def copyrights_for_path(path) copyrights_for_modifications(@paths[path]) end |
#extract(root = Dir.pwd) ⇒ Object
Extract the authorship from the given root directory.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/bake/modernize/license.rb', line 228 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, , time| add(path, , time) end end walk(Rugged::Repository.discover(root), mailmap: mailmap, skip_list: skip_list) return self end |
#sorted_authors ⇒ Object
Authors, sorted by contribution date.
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/bake/modernize/license.rb', line 244 def = Hash.new{|h,k| h[k] = 0} @commits.each do |key, modifications| modifications.map(&:full_name).uniq.each do |full_name| [full_name] += 1 end end return .sort_by{|k,v| [-v, k]}.map(&:first) end |