diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/commands/dbconsole.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators.rb | 46 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 5 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 8 |
4 files changed, 56 insertions, 7 deletions
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 8957f11724..5bbaf725df 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -55,7 +55,7 @@ module Rails end case config["adapter"] - when "mysql" + when /^mysql/ args = { 'host' => '--host', 'port' => '--port', @@ -114,4 +114,4 @@ end # Has to set the RAILS_ENV before config/application is required if ARGV.first && !ARGV.first.index("-") && env = ARGV.first ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env -end
\ No newline at end of file +end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 9bc019b152..fe8a6c0b94 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -166,6 +166,38 @@ module Rails end end + def self.hidden_namespaces + @hidden_namespaces ||= begin + orm = options[:rails][:orm] + test = options[:rails][:test_framework] + template = options[:rails][:template_engine] + + [ + "rails", + "#{orm}:migration", + "#{orm}:model", + "#{orm}:observer", + "#{test}:controller", + "#{test}:helper", + "#{test}:integration", + "#{test}:mailer", + "#{test}:model", + "#{test}:observer", + "#{test}:scaffold", + "#{test}:view", + "#{template}:controller", + "#{template}:scaffold" + ] + end + end + + class << self + def hide_namespaces(*namespaces) + hidden_namespaces.concat(namespaces) + end + alias hide_namespace hide_namespaces + end + # Show help message with available generators. def self.help(command = 'generate') lookup! @@ -197,9 +229,7 @@ module Rails rails.delete("app") print_list("rails", rails) - groups.delete("active_record") if options[:rails][:orm] == :active_record - groups.delete("test_unit") if options[:rails][:test_framework] == :test_unit - groups.delete("erb") if options[:rails][:template_engine] == :erb + hidden_namespaces.each {|n| groups.delete(n.to_s) } groups.sort.each { |b, n| print_list(b, n) } end @@ -208,9 +238,17 @@ module Rails # Prints a list of generators. def self.print_list(base, namespaces) #:nodoc: + namespaces = namespaces.reject do |n| + hidden_namespaces.include?(n) + end + return if namespaces.empty? puts "#{base.camelize}:" - namespaces.each { |namespace| puts(" #{namespace}") } + + namespaces.each do |namespace| + puts(" #{namespace}") + end + puts end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 10d8b8f85a..0a0b033738 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -200,6 +200,9 @@ module Rails def initialize(*args) raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank? + + @original_wd = Dir.pwd + super if !options[:skip_activerecord] && !DATABASES.include?(options[:database]) @@ -316,7 +319,7 @@ module Rails if URI(path).is_a?(URI::HTTP) contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read } else - contents = open(path) {|io| io.read } + contents = open(File.expand_path(path, @original_wd)) {|io| io.read } end prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1a93867013..8743defe82 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -238,6 +238,14 @@ class CustomAppGeneratorTest < Rails::Generators::TestCase assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] end + def test_builder_option_with_relative_path + here = File.expand_path(File.dirname(__FILE__)) + FileUtils.cd(here) + run_generator([destination_root, "-b", "../fixtures/lib/simple_builder.rb"]) + (DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path } + assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] + end + def test_builder_option_with_tweak_app_builder FileUtils.cd(Rails.root) run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"]) |