Class: Bake::Modernize::License::Contributors

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

Overview

Extract contributors from a YAML file which can be generated from another repository.

Constant Summary collapse

DEFAULT_PATH =

The default path is the root of the repository and for authors who have contributed to the entire repository or unspecified paths in the past.

"."

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContributors

Create a new, empty, contributors list.



124
125
126
# File 'lib/bake/modernize/license.rb', line 124

def initialize
	@contributions = []
end

Instance Attribute Details

#The list of paths from a given contribution.(listofpathsfromagivencontribution.) ⇒ Object (readonly)



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/bake/modernize/license.rb', line 148

def paths_for(contribution)
	return to_enum(:paths_for, contribution) unless block_given?
	
	if path = contribution[:path]
		yield path
	# elsif paths = contribution[:paths]
	# 	paths.each do |path|
	# 		yield path
	# 	end
	else
		yield DEFAULT_PATH
	end
end

Class Method Details

.for(root) ⇒ Object

Load contributors from a directory.



113
114
115
116
117
118
119
120
121
# File 'lib/bake/modernize/license.rb', line 113

def self.for(root)
	full_path = File.join(root, ".contributors.yaml")
	
	if File.exist?(full_path)
		contributors = self.new
		contributors.extract(full_path)
		return contributors
	end
end

Instance Method Details

#each(&block) ⇒ Object

Iterate over each contribution.



129
130
131
132
133
134
135
136
137
138
# File 'lib/bake/modernize/license.rb', line 129

def each(&block)
	@contributions.each do |contribution|
		author = contribution[:author]
		time = contribution[:time]
		
		paths_for(contribution) do |path|
			yield path, author, time
		end
	end
end

#extract(path) ⇒ Object

Extract the contributors from the given path.



141
142
143
144
145
# File 'lib/bake/modernize/license.rb', line 141

def extract(path)
	@contributions.concat(
		YAML.load_file(path, aliases: true, symbolize_names: true, permitted_classes: [Symbol, Date, Time])
	)
end

#paths_for(contribution) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/bake/modernize/license.rb', line 148

def paths_for(contribution)
	return to_enum(:paths_for, contribution) unless block_given?
	
	if path = contribution[:path]
		yield path
	# elsif paths = contribution[:paths]
	# 	paths.each do |path|
	# 		yield path
	# 	end
	else
		yield DEFAULT_PATH
	end
end