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.
219 220 221 222 |
# File 'lib/bake/modernize/license.rb', line 219 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.
228 229 230 |
# File 'lib/bake/modernize/license.rb', line 228 def commits @commits end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
225 226 227 |
# File 'lib/bake/modernize/license.rb', line 225 def paths @paths end |
#The mapping of commits to modifications.(mappingofcommitstomodifications.) ⇒ Object (readonly)
228 |
# File 'lib/bake/modernize/license.rb', line 228 attr :commits |
#The mapping of paths to modifications.(mappingofpathstomodifications.) ⇒ Object (readonly)
225 |
# File 'lib/bake/modernize/license.rb', line 225 attr :paths |
Instance Method Details
#add(path, author, time, id = nil) ⇒ Object
Add a modification to the authorship.
231 232 233 234 235 236 |
# File 'lib/bake/modernize/license.rb', line 231 def add(path, , time, id = nil) modification = Modification.new(, time, path, id) @commits[modification.key] << modification @paths[path] << modification end |
#copyrights ⇒ Object
All copyrights.
268 269 270 |
# File 'lib/bake/modernize/license.rb', line 268 def copyrights copyrights_for_modifications(@paths.values.flatten) end |
#copyrights_for_modifications(modifications) ⇒ Object
All copyrights for a given modification.
278 279 280 281 282 283 284 |
# File 'lib/bake/modernize/license.rb', line 278 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.
273 274 275 |
# File 'lib/bake/modernize/license.rb', line 273 def copyrights_for_path(path) copyrights_for_modifications(@paths[path]) end |
#extract(root = Dir.pwd) ⇒ Object
Extract the authorship from the given root directory.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/bake/modernize/license.rb', line 239 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.
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/bake/modernize/license.rb', line 255 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 |