Permalink
Browse files

Bumped up to 0.3

* Use OptionParser
* Added --skip-migration option (for early stages of development)
  • Loading branch information...
1 parent c6d7e96 commit 409875d4f96f9444d7d2700931b61dd5f803cd75 @hiroshi committed Apr 8, 2009
Showing with 44 additions and 27 deletions.
  1. +5 −0 CHANGELOG
  2. +8 −4 lib/rename_refactoring.rb
  3. +31 −23 lib/script_refactor.rb
View
@@ -1,3 +1,8 @@
+*0.3*
+
+* Added --skip-migration option (for early stages of development) [Hiroshi Saito]
+* Skip 'db' directory, not only 'migration' (should not touch *.sqlite3 nor schema.rb) [Hiroshi Saito]
+
*0.2*
* Don't rewrite content to file being parsed if no matches were found in that file. [T.J. Sheehy] 02cb9c8
View
@@ -12,7 +12,7 @@ def initialize(rails_root, from, to)
@to = to
end
- def apply
+ def apply(options={})
# scm
case
when File.directory?(".git")
@@ -80,9 +80,13 @@ def rename_cmd(src, dst); "mv #{src} #{dst}"; end
end
end
- puts 'generating rename migration'
- migraton_generator = MigrationGenerator.new(@rails_root)
- migraton_generator.generate_rename_table_migration(@from.camelize, @to.camelize)
+ unless options[:skip_migration]
+ puts 'generating rename migration'
+ migraton_generator = MigrationGenerator.new(@rails_root)
+ migraton_generator.generate_rename_table_migration(@from.camelize, @to.camelize)
+ else
+ puts 'SKIP: generating rename migration'
+ end
puts "\nNOTE: If you want to revert them:" if scm
case scm
View
@@ -1,38 +1,46 @@
+require 'optparse'
require File.dirname(__FILE__) + '/rename_refactoring'
-module Refactor
- VERSION = "0.2"
-end
-# usage
-if ARGV.size != 3
- puts <<-USAGE
-script-refactor #{Refactor::VERSION}
+# == parse command line arguments
+options = {}
+opts = OptionParser.new do |opts|
+ opts.set_summary_indent(' ')
+ opts.program_name = "script/refactor"
+ opts.version = "0.3"
+ opts.banner = "Usage: #{opts.program_name} [OPTIONS] type from to"
+ opts.on_head <<-HEAD
-Help refactoring application:
+Help rails application refactoring:
* Renaming files with scm aware manner
* Replacing class names, variable names as possible
* Generate renaming migration file
THIS SCRIPT MAY DESTRUCT FILES AND/OR DIRECTORIES OF YOUR RAILS APPLICATION.
BE SURE YOUR CHANGES ARE COMMITED OR BACKED UP!
+ HEAD
+ opts.separator "Possible types:"
+ opts.separator " resource: Replace resource name."
+ opts.separator ""
+ opts.separator "Supported SCM: git, svn"
+ opts.separator ""
+ opts.separator "OPTIONS:"
+ opts.on("--skip-migration", "Don't generate table renaming migration files") {|v| options[:skip_migration] = v }
+ opts.separator ""
+ opts.separator "Examples:"
+ opts.separator " #{opts.program_name} resource user person"
+end
-Usage:
- #{$0} type from to
-
-Possible types:
-
- resource: Replace resource name.
-
-Supported SCM: git, svn
-
-Examples:
- #{$0} resource user person
+begin
+ opts.parse!
+rescue OptionParser::InvalidOption
+end
- USAGE
+if ARGV.size != 3
+ puts opts
exit 1
end
-
-# arguments
type, from, to = ARGV
+
+#== do
rename = RenameRefactoring.new(File.expand_path('.'), from, to)
-rename.apply
+rename.apply(options)

0 comments on commit 409875d

Please sign in to comment.