Module: AddCopyrightAuthor

Defined in:
lib/copyright_author.rb

Class Method Summary collapse

Class Method Details

.process(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/copyright_author.rb', line 4

def self.process(options)

  # defaults
  name  = options[0] || "NO AUTHOR"
  directory = options[1] || Dir.pwd

  prefix = "Author - #{name} | Copyright(c) #{Time.now.year}. All rights reserved.\n"

	extensions = {
'rb' => '# {text}',
'rake' => '# {text}',
'haml' => '-# {text}',
	}

	count = 0
	extensions.each do |ext, comment_style|
rbfiles = File.join(directory ,'**', '*.'+ext)
Dir.glob(rbfiles).each do |filename|
	file = File.new(filename, "r+")

	lines = file.readlines

	# remove current copyright comment(s)
	while lines[0] && (lines[0].starts_with?(comment_style.sub('{text}', ' copyright')))
		lines.shift
	end

	# set current copyright
	lines.insert(0,comment_style.sub('{text}', prefix))
	count += 1

	file.pos = 0
	file.puts(lines.join)
	file.close
end
	end
  puts "Copyright set for #{count} source files"
end