diff options
author | wangjohn <wangjohn@mit.edu> | 2013-08-29 00:33:23 -0500 |
---|---|---|
committer | wangjohn <wangjohn@mit.edu> | 2013-08-29 00:34:42 -0500 |
commit | 21e68853fd7470eada2b970e58e5d8ed05098246 (patch) | |
tree | 70f9dc6cfdb2d141369cba5260ac8ba58dd2379b | |
parent | a7b845c27f32b6e00a7bf87aa555c41808b3e1a8 (diff) | |
download | rails-21e68853fd7470eada2b970e58e5d8ed05098246.tar.gz rails-21e68853fd7470eada2b970e58e5d8ed05098246.tar.bz2 rails-21e68853fd7470eada2b970e58e5d8ed05098246.zip |
Small refactoring changes to generators.
Made a method name clearer (added a bang to the end to show that it
mutates arguments) and extracted indentation into its own method.
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/controller/controller_generator.rb | 10 |
2 files changed, 9 insertions, 5 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 041bfcb733..a336fd47f7 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -341,7 +341,7 @@ module Rails def handle_rails_rc! unless argv.delete("--no-rc") - insert_railsrc(railsrc) + insert_railsrc_into_argv!(railsrc) end end @@ -353,7 +353,7 @@ module Rails end end - def insert_railsrc(railsrc) + def insert_railsrc_into_argv!(railsrc) if File.exist?(railsrc) extra_args_string = File.read(railsrc) extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 822f35fb42..11dc598161 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -32,23 +32,27 @@ module Rails # namespace :foo do # namespace :bar do namespace_ladder = class_path.each_with_index.map do |ns, i| - %{#{" " * i * 2}namespace :#{ns} do\n } + %{#{indent(i)}namespace :#{ns} do\n } end.join # Create route # get "baz/index" - route = %{#{" " * depth * 2}get "#{file_name}/#{action}"\n} + route = %{#{indent(depth)}get "#{file_name}/#{action}"\n} # Create `end` ladder # end # end end_ladder = (1..depth).reverse_each.map do |i| - "#{" " * i * 2}end\n" + "#{indent(i)}end\n" end.join # Combine the 3 parts to generate complete route entry namespace_ladder + route + end_ladder end + + def indent(depth) + " " * depth * 2 + end end end end |