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.



198
199
200
201
# File 'lib/bake/modernize/license.rb', line 198

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.



207
208
209
# File 'lib/bake/modernize/license.rb', line 207

def commits
  @commits
end

#pathsObject (readonly)

Returns the value of attribute paths.



204
205
206
# File 'lib/bake/modernize/license.rb', line 204

def paths
  @paths
end

#The mapping of commits to modifications.(mappingofcommitstomodifications.) ⇒ Object (readonly)



207
# File 'lib/bake/modernize/license.rb', line 207

attr :commits

#The mapping of paths to modifications.(mappingofpathstomodifications.) ⇒ Object (readonly)



204
# File 'lib/bake/modernize/license.rb', line 204

attr :paths

Instance Method Details

#add(path, author, time, id = nil) ⇒ Object

Add a modification to the authorship.



210
211
212
213
214
215
# File 'lib/bake/modernize/license.rb', line 210

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.



247
248
249
# File 'lib/bake/modernize/license.rb', line 247

def copyrights
	copyrights_for_modifications(@paths.values.flatten)
end

#copyrights_for_modifications(modifications) ⇒ Object

All copyrights for a given modification.



257
258
259
260
261
262
263
# File 'lib/bake/modernize/license.rb', line 257

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.



252
253
254
# File 'lib/bake/modernize/license.rb', line 252

def copyrights_for_path(path)
	copyrights_for_modifications(@paths[path])
end

#extract(root = Dir.pwd) ⇒ Object

Extract the authorship from the given root directory.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/bake/modernize/license.rb', line 218

def extract(root = Dir.pwd)
	mailmap = Mailmap.for(root)
	skip_list = SkipList.for(root)
	
	if contributors = Contributors.for(root)
		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.



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/bake/modernize/license.rb', line 234

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