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)
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, |
rbfiles = File.join(directory ,'**', '*.'+ext)
Dir.glob(rbfiles).each do |filename|
file = File.new(filename, "r+")
lines = file.readlines
while lines[0] && (lines[0].starts_with?(.sub('{text}', ' copyright')))
lines.shift
end
lines.insert(0,.sub('{text}', prefix))
count += 1
file.pos = 0
file.puts(lines.join)
file.close
end
end
puts "Copyright set for #{count} source files"
end
|