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.
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
#commits ⇒ Object (readonly)
Returns the value of attribute commits.
207 208 209 |
# File 'lib/bake/modernize/license.rb', line 207 def commits @commits end |
#paths ⇒ Object (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, , time, id = nil) modification = Modification.new(, time, path, id) @commits[modification.key] << modification @paths[path] << modification end |
#copyrights ⇒ Object
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) = 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.
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, , 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.
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/bake/modernize/license.rb', line 234 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 |