Skip to content

Instantly share code, notes, and snippets.

@itarato
Last active December 13, 2017 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarato/0b1a2eec47eff8ab8a4904f0a547aef6 to your computer and use it in GitHub Desktop.
Save itarato/0b1a2eec47eff8ab8a4904f0a547aef6 to your computer and use it in GitHub Desktop.
Adds frozen headers to all ruby files in a folder.
# Call: ruby add_frozen_heading.rb PATH_TO_FOLDER
dir = ARGV[0] || ''
if !Dir.exist?(dir)
puts 'Missing folder.'
exit
end
def check_headers(dir)
# puts "Inspect #{dir}"
Dir.foreach(dir) do |subdir|
next if subdir == '.' || subdir == '..'
fullpath = "#{dir}/#{subdir}"
if File.stat(fullpath).directory?
check_headers(fullpath)
elsif fullpath[-3..-1] == '.rb'
begin
first_line = File.open(fullpath, &:readline)
unless first_line.strip == '# frozen_string_literal: true'
content = File.read(fullpath)
File.open(fullpath, 'wb') { |f| f.write("# frozen_string_literal: true\n#{content}")}
puts "Patched: #{fullpath}"
end
rescue
end
end
end
end
check_headers(dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment