Module: ModernizeHashes
Constant Summary collapse
- SUPPORTED_EXTENSIONS =
%w{ rb haml erb slim }
Instance Method Summary collapse
Instance Method Details
#replace_hashes_in_file(file) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/modernize-hashes.rb', line 17 def replace_hashes_in_file(file) replacements = File.open(file).read.gsub /:([a-z_]+)(\s+)?=>(\s+)?/, '\1: ' File.open(file, 'w') { |f| f.write replacements } rescue => e raise e.class, "#{e.} in #{file}" end |
#run! ⇒ Object
13 14 15 |
# File 'lib/modernize-hashes.rb', line 13 def run! Dir["**/*"].select { |file| supported_extension? file }.each { |file| replace_hashes_in_file file } end |
#supported_extension?(file) ⇒ Boolean
24 25 26 |
# File 'lib/modernize-hashes.rb', line 24 def supported_extension?(file) SUPPORTED_EXTENSIONS.map { |e| ".#{e}" }.include? File.extname(file) end |