lib/tasks/rename_class.rake in effective_developer-0.2.6 vs lib/tasks/rename_class.rake in effective_developer-0.2.7

- old
+ new

@@ -9,11 +9,11 @@ source = args.source.to_s.downcase.singularize target = args.target.to_s.downcase.singularize puts "=== Renaming class '#{source.classify}' to '#{target.classify}'" - whitelist = ['app/', 'db/', 'lib/', 'test/'].compact + whitelist = ['app/', 'config/routes.rb', 'config/locales/', 'db/', 'lib/', 'test/'].compact blacklist = ['db/schema.rb', ('db/migrate' if args.db == 'skipdb')].compact # Rename any directories in the app Dir.glob('**/*').each do |path| next unless whitelist.any? { |ok| path.start_with?(ok) } @@ -26,11 +26,11 @@ File.rename(path, changed) puts "renamed: #{path} => #{changed}" end end - # For every file in the app + # Rename any files in the app Dir.glob('**/*.*').each do |path| next unless whitelist.any? { |ok| path.start_with?(ok) } next if blacklist.any? { |nope| path.start_with?(nope) } changed = path.gsub(source.pluralize, target.pluralize).gsub(source, target) @@ -39,19 +39,27 @@ File.rename(path, changed) puts "renamed: #{path} => #{changed}" end end - # For every file in the app + # Search and replace in all files + subs = { + source.classify.pluralize => target.classify.pluralize, + source.classify => target.classify, + source.pluralize => target.pluralize, + source => target + } + + if source.include?('_') + subs[source.gsub('_', '-')] ||= target + end + Dir.glob('**/*.*').each do |path| next unless whitelist.any? { |ok| path.start_with?(ok) } next if blacklist.any? { |nope| path.start_with?(nope) } writer = Effective::CodeWriter.new(path) do |w| - w.gsub!(source.classify.pluralize, target.classify.pluralize) - w.gsub!(source.classify, target.classify) - w.gsub!(source.pluralize, target.pluralize) - w.gsub!(source, target) + subs.each { |k, v| w.gsub!(k, v) } end puts "updated: #{path}" if writer.changed? end