Permalink
Browse files

Renamed Util to RenamRefactoring

  • Loading branch information...
1 parent 02cb9c8 commit d3d8c36ef4b8c27b030e5fcab0f29a36e122a707 @tjsheehy tjsheehy committed Mar 29, 2009
@@ -2,30 +2,34 @@
require "rubygems"
require "active_support"
-class Util
+class RenameRefactoring
- def self.apply_rename_refactoring(type, from, to)
-
+ def initialize(from, to)
+ @from = from
+ @to = to
+ end
+
+ def apply
# scm
case
when File.directory?(".git")
scm = :git
- def self.rename_cmd(src, dst); "git mv #{src} #{dst}"; end
+ def rename_cmd(src, dst); "git mv #{src} #{dst}"; end
when File.directory?(".svn")
scm = :svn
- def self.rename_cmd(src, dst); "svn mv #{src} #{dst}"; end
+ def rename_cmd(src, dst); "svn mv #{src} #{dst}"; end
else
- def self.rename_cmd(src, dst); "mv #{src} #{dst}"; end
+ def rename_cmd(src, dst); "mv #{src} #{dst}"; end
end
renames = {
- "test/unit/#{from}_test.rb" => "test/unit/#{to}_test.rb",
- "test/functional/#{from.pluralize}_controller_test.rb" => "test/functional/#{to.pluralize}_controller_test.rb",
- "test/fixtures/#{from.pluralize}.yml" => "test/fixtures/#{to.pluralize}.yml",
- "app/views/#{from.pluralize}" => "app/views/#{to.pluralize}",
- "app/models/#{from}.rb" => "app/models/#{to}.rb",
- "app/helpers/#{from.pluralize}_helper.rb" => "app/helpers/#{to.pluralize}_helper.rb",
- "app/controllers/#{from.pluralize}_controller.rb" => "app/controllers/#{to.pluralize}_controller.rb",
+ "test/unit/#{@from}_test.rb" => "test/unit/#{@to}_test.rb",
+ "test/functional/#{@from.pluralize}_controller_test.rb" => "test/functional/#{@to.pluralize}_controller_test.rb",
+ "test/fixtures/#{@from.pluralize}.yml" => "test/fixtures/#{@to.pluralize}.yml",
+ "app/views/#{@from.pluralize}" => "app/views/#{@to.pluralize}",
+ "app/models/#{@from}.rb" => "app/models/#{@to}.rb",
+ "app/helpers/#{@from.pluralize}_helper.rb" => "app/helpers/#{@to.pluralize}_helper.rb",
+ "app/controllers/#{@from.pluralize}_controller.rb" => "app/controllers/#{@to.pluralize}_controller.rb",
}
puts "Renaming files and directories:"
@@ -39,10 +43,10 @@ def self.rename_cmd(src, dst); "mv #{src} #{dst}"; end
puts "\nReplacing class and variables:"
replaces = {
- from => to,
- from.classify => to.classify,
- from.pluralize => to.pluralize,
- from.classify.pluralize => to.classify.pluralize,
+ @from => @to,
+ @from.classify => @to.classify,
+ @from.pluralize => @to.pluralize,
+ @from.classify.pluralize => @to.classify.pluralize,
}
replaces.each do |f,t|
puts "#{f} -> #{t}"
@@ -74,7 +78,7 @@ def self.rename_cmd(src, dst); "mv #{src} #{dst}"; end
puts 'generating rename migration'
migraton_generator = MigrationGenerator.new(@rails_root)
- migraton_generator.generate_rename_table_migration('from', 'to')
+ migraton_generator.generate_rename_table_migration(@from, @to)
puts "\nNOTE: If you want to revert them:" if scm
case scm
View
@@ -1,7 +1,6 @@
=begin
TODO:
* Please refactor me
-* Ignore db directory and create migration?
=end
module Refactor
VERSION = "0.1"
@@ -38,4 +37,5 @@ module Refactor
# arguments
type, from, to = ARGV
-Util.apply_rename_refactoring(type, from, to)
+rename = RenameRefactoring.new(@from, @to)
+rename.apply
File renamed without changes.

0 comments on commit d3d8c36

Please sign in to comment.