Skip to content
Browse files

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.
  • Loading branch information...
1 parent a7b845c commit 21e68853fd7470eada2b970e58e5d8ed05098246 @wangjohn wangjohn committed Aug 29, 2013
View
4 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -341,7 +341,7 @@ def handle_invalid_command!(argument)
def handle_rails_rc!
unless argv.delete("--no-rc")
- insert_railsrc(railsrc)
+ insert_railsrc_into_argv!(railsrc)
end
end
@@ -353,7 +353,7 @@ def railsrc
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
View
10 railties/lib/rails/generators/rails/controller/controller_generator.rb
@@ -32,23 +32,27 @@ def generate_routing_code(action)
# 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

0 comments on commit 21e6885

Please sign in to comment.
Something went wrong with that request. Please try again.