Class: Bake::Modernize::License::Authorship

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/modernize/license.rb

Overview

Represents the authorship of a repository.

Defined Under Namespace

Classes: Copyright, Modification

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuthorship

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

#commitsObject (readonly)

Returns the value of attribute commits.



228
229
230
# File 'lib/bake/modernize/license.rb', line 228

def commits
  @commits
end

#pathsObject (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, author, time, id = nil)
	modification = Modification.new(author, time, path, id)
	
	@commits[modification.key] << modification
	@paths[path] << modification
end

#copyrightsObject

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)
	authors = modifications.group_by{|modification| modification.full_name}
	
	authors.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, author, time|
			add(path, author, time)
		end
	end
	
	walk(Rugged::Repository.discover(root), mailmap: mailmap, skip_list: skip_list)
	
	return self
end

#sorted_authorsObject

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 sorted_authors
	authors = Hash.new{|h,k| h[k] = 0}
	
	@commits.each do |key, modifications|
		modifications.map(&:full_name).uniq.each do |full_name|
			authors[full_name] += 1
		end
	end
	
	return authors.sort_by{|k,v| [-v, k]}.map(&:first)
end