From b1999be5a7efd67e2602c37ed898aa8433661863 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Feb 2005 01:45:35 +0000 Subject: A hopefully more successful attempt at the Routing branch merge git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/dispatcher.rb | 50 +++++----------- railties/lib/rails_generator.rb | 6 +- railties/lib/rails_generator/base.rb | 21 +++++-- .../generators/applications/app/app_generator.rb | 6 +- .../components/controller/controller_generator.rb | 5 +- .../controller/templates/functional_test.rb | 3 +- .../components/mailer/mailer_generator.rb | 21 ++++--- .../generators/components/model/model_generator.rb | 5 ++ .../components/model/templates/fixtures.yml | 6 +- .../components/model/templates/unit_test.rb | 4 +- .../components/scaffold/scaffold_generator.rb | 29 ++++++--- .../scaffold/templates/functional_test.rb | 18 +++--- .../components/scaffold/templates/view_list.rhtml | 2 +- railties/lib/rails_generator/lookup.rb | 30 ++++------ railties/lib/rails_generator/options.rb | 19 +++--- railties/lib/rails_generator/scripts.rb | 28 +++++---- railties/lib/rails_generator/scripts/destroy.rb | 4 -- railties/lib/rails_generator/scripts/generate.rb | 4 -- railties/lib/rails_generator/scripts/update.rb | 3 - railties/lib/webrick_server.rb | 70 +--------------------- 20 files changed, 138 insertions(+), 196 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 566b031295..007b407005 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -27,53 +27,31 @@ class Dispatcher class < exception ActionController::Base.process_with_exception(request, response, exception).out ensure - reset_application if Dependencies.load? - Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) + reset_application end end private - def reset_application - Dependencies.clear - Dependencies.remove_subclasses_for(ActiveRecord::Base, ActiveRecord::Observer, ActionController::Base) + def prepare_application + ActionController::Routing::Routes.reload if Dependencies.load? + Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT) + Controllers.const_load!("application") unless Controllers.const_defined?(:ApplicationController) end - def controller_path(controller_name, module_name = nil) - if module_name - "#{module_name}/#{controller_name.underscore}_controller" - else - "#{controller_name.underscore}_controller" + def reset_application + if Dependencies.load? + Controllers.clear + Dependencies.clear + Dependencies.remove_subclasses_for(ActiveRecord::Base, ActiveRecord::Observer, ActionController::Base) end - end - - def controller_class(controller_name) - Object.const_get(controller_class_name(controller_name)) - end - - def controller_class_name(controller_name) - "#{controller_name.camelize}Controller" - end - - def controller_name(parameters) - parameters["controller"].downcase.gsub(/[^_a-zA-Z0-9]/, "").untaint - end - def module_name(parameters) - parameters["module"].downcase.gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"] + Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) end end end \ No newline at end of file diff --git a/railties/lib/rails_generator.rb b/railties/lib/rails_generator.rb index 0875a22dee..c46989819d 100644 --- a/railties/lib/rails_generator.rb +++ b/railties/lib/rails_generator.rb @@ -23,7 +23,7 @@ $:.unshift(File.dirname(__FILE__)) -require 'support/core_ext' +require 'rails_generator/support/core_ext' require 'rails_generator/base' require 'rails_generator/lookup' @@ -31,3 +31,7 @@ require 'rails_generator/commands' Rails::Generator::Base.send(:include, Rails::Generator::Lookup) Rails::Generator::Base.send(:include, Rails::Generator::Commands) + +# Set up a default logger for convenience. +require 'rails_generator/simple_logger' +Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(STDOUT) diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb index 065ce63966..92a54e2453 100644 --- a/railties/lib/rails_generator/base.rb +++ b/railties/lib/rails_generator/base.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../support/class_attribute_accessors' -require File.dirname(__FILE__) + '/../support/inflector' +require File.dirname(__FILE__) + '/support/class_attribute_accessors' +require File.dirname(__FILE__) + '/support/inflector' require File.dirname(__FILE__) + '/options' require File.dirname(__FILE__) + '/manifest' require File.dirname(__FILE__) + '/spec' @@ -69,8 +69,8 @@ module Rails @source_root = options[:source] || File.join(spec.path, 'templates') if options[:destination] @destination_root = options[:destination] - elsif Object.const_defined?(:RAILS_ROOT) - @destination_root = Object.const_get(:RAILS_ROOT) + elsif defined? ::RAILS_ROOT + @destination_root = ::RAILS_ROOT end # Silence the logger if requested. @@ -173,11 +173,20 @@ module Rails def assign_names!(name) @name = name base_name, @class_path, @class_nesting = extract_modules(@name) - @class_name, @singular_name, @plural_name = inflect_names(base_name) + @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) + if @class_nesting.empty? + @class_name = @class_name_without_nesting + else + @class_name = "#{@class_nesting}::#{@class_name_without_nesting}" + end end + # Extract modules from filesystem-style or ruby-style path: + # good/fun/stuff + # Good::Fun::Stuff + # produce the same results. def extract_modules(name) - modules = name.split('/') + modules = name.include?('/') ? name.split('/') : name.split('::') name = modules.pop path = modules.map { |m| m.underscore } nesting = modules.map { |m| m.camelize }.join('::') diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 0beb11b237..4a04757ddd 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -1,15 +1,16 @@ +require 'rbconfig' + class AppGenerator < Rails::Generator::Base DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) default_options :gem => true, :shebang => DEFAULT_SHEBANG - mandatory_options :source => "#{File.dirname(__FILE__)}/../.." + mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." def initialize(runtime_args, runtime_options = {}) super usage if args.empty? @destination_root = args.shift - puts "eek! #{destination_root.inspect}" end def manifest @@ -32,6 +33,7 @@ class AppGenerator < Rails::Generator::Base # database.yml and .htaccess m.template "configs/database.yml", "config/database.yml" + m.template "configs/routes.rb", "config/routes.rb" m.template "configs/apache.conf", "public/.htaccess" # Environments diff --git a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb index 1f7e69d124..d537031fea 100644 --- a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb +++ b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb @@ -4,8 +4,11 @@ class ControllerGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" - # Views directory even if there are no actions. + # Controller, helper, views, and test directories. + m.directory File.join('app/controllers', class_path) + m.directory File.join('app/helpers', class_path) m.directory File.join('app/views', class_path, file_name) + m.directory File.join('test/functional', class_path) # Controller class, functional test, and helper class. m.template 'controller.rb', diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb index c975cb3ce3..76e2b33ba5 100644 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb @@ -7,7 +7,8 @@ class <%= class_name %>Controller; def rescue_action(e) raise e end; end class <%= class_name %>ControllerTest < Test::Unit::TestCase def setup @controller = <%= class_name %>Controller.new - @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new end # Replace this with your real tests. diff --git a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb index 81d4599f7f..d8ddb43644 100644 --- a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb +++ b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb @@ -4,21 +4,28 @@ class MailerGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions class_name, "#{class_name}Test" - # Mailer class and unit test. - m.template "mailer.rb", "app/models/#{file_name}.rb" - m.template "unit_test.rb", "test/unit/#{file_name}_test.rb" + # Mailer, view, test, and fixture directories. + m.directory File.join('app/models', class_path) + m.directory File.join('app/views', class_path, file_name) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/fixtures', class_path, table_name) - # Views and fixtures directories. - m.directory "app/views/#{file_name}" - m.directory "test/fixtures/#{table_name}" + # Mailer class and unit test. + m.template "mailer.rb", File.join('app/models', + class_path, + "#{file_name}.rb") + m.template "unit_test.rb", File.join('test/unit', + class_path, + "#{file_name}_test.rb") # View template and fixture for each action. actions.each do |action| m.template "view.rhtml", - "app/views/#{file_name}/#{action}.rhtml", + File.join('app/views', class_path, file_name, "#{action}.rhtml"), :assigns => { :action => action } m.template "fixture.rhtml", "test/fixtures/#{table_name}/#{action}", + File.join('test/fixtures', class_path, table_name, action), :assigns => { :action => action } end end diff --git a/railties/lib/rails_generator/generators/components/model/model_generator.rb b/railties/lib/rails_generator/generators/components/model/model_generator.rb index 32577d08a3..c3407ca283 100644 --- a/railties/lib/rails_generator/generators/components/model/model_generator.rb +++ b/railties/lib/rails_generator/generators/components/model/model_generator.rb @@ -4,6 +4,11 @@ class ModelGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions class_name, "#{class_name}Test" + # Model, test, and fixture directories. + m.directory File.join('app/models', class_path) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/fixtures', class_path) + # Model class, unit test, and fixtures. m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") diff --git a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml index fc3185dc46..6285727968 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml +++ b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml @@ -1,10 +1,8 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html # Set the $base_id variable in the setup method of your tests. # It's used to ensure that ids don't clash in some databases. -<%% $base_id ||= 100000 %> - first_<%= singular_name %>: - id: <%%= $base_id %> + id: 1 another_<%= singular_name %>: - id: <%%= $base_id + 1 %> + id: 2 diff --git a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb index db0fbf5d33..e8714b589a 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb @@ -4,11 +4,11 @@ class <%= class_name %>Test < Test::Unit::TestCase fixtures :<%= table_name %> def setup - $base_id = 1000001 + @<%= singular_name %> = <%= class_name %>.find(1) end # Replace this with your real tests. def test_truth - assert true + assert_kind_of <%= class_name %>, @<%= singular_name %> end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index 4445995b46..abf9d79ffe 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -41,7 +41,12 @@ class ScaffoldGenerator < Rails::Generator::NamedBase super @controller_name = args.shift || @name.pluralize base_name, @controller_class_path, @controller_class_nesting = extract_modules(@controller_name) - @controller_class_name, @controller_singular_name, @controller_plural_name = inflect_names(base_name) + @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) + if @controller_class_nesting.empty? + @controller_class_name = @controller_class_name_without_nesting + else + @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" + end end def manifest @@ -52,8 +57,12 @@ class ScaffoldGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper" - # Views directory. + # Controller, helper, views, and test directories. + m.directory File.join('app/controllers', controller_class_path) + m.directory File.join('app/helpers', controller_class_path) m.directory File.join('app/views', controller_class_path, controller_file_name) + m.directory File.join('test/functional', controller_class_path) + # Controller class, functional test, helper, and views. m.template 'controller.rb', @@ -79,7 +88,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase scaffold_views.each do |action| m.template "view_#{action}.rhtml", File.join('app/views', - controller_class_path, controller_file_name, + controller_class_path, + controller_file_name, "#{action}.rhtml"), :assigns => { :action => action } end @@ -103,7 +113,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase unscaffolded_actions.each do |action| m.template "controller:view.rhtml", File.join('app/views', - controller_class_path, controller_file_name, + controller_class_path, + controller_file_name, "#{action}.rhtml"), :assigns => { :action => action } end @@ -153,9 +164,13 @@ class ScaffoldGenerator < Rails::Generator::NamedBase end def model_instance - unless Object.const_defined?(class_name) - Object.const_set(class_name, Class.new(ActiveRecord::Base)) + base = class_nesting.split('::').inject(Object) do |base, nested| + break base.const_get(nested) if base.const_defined?(nested) + base.const_set(nested, Module.new) + end + unless base.const_defined?(@class_name_without_nesting) + base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base)) end - Object.const_get(class_name).new + class_name.constantize.new end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb index ea9c8e4e94..32185fb715 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb @@ -8,9 +8,9 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase fixtures :<%= table_name %> def setup - $base_id = 1000001 @controller = <%= controller_class_name %>Controller.new - @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new end <% for action in unscaffolded_actions -%> @@ -34,7 +34,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase end def test_show<%= suffix %> - process :show<%= suffix %>, 'id' => $base_id + process :show<%= suffix %>, 'id' => 1 assert_rendered_file 'show' assert_template_has '<%= singular_name %>' assert_valid_record '<%= singular_name %>' @@ -56,25 +56,25 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase end def test_edit<%= suffix %> - process :edit<%= suffix %>, 'id' => $base_id + process :edit<%= suffix %>, 'id' => 1 assert_rendered_file 'edit<%= suffix %>' assert_template_has '<%= singular_name %>' assert_valid_record '<%= singular_name %>' end def test_update<%= suffix %> - process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => $base_id } - assert_redirected_to :action => 'show<%= suffix %>', :id => $base_id + process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => 1 } + assert_redirected_to :action => 'show<%= suffix %>', :id => 1 end def test_destroy<%= suffix %> - assert_not_nil <%= class_name %>.find($base_id) + assert_not_nil <%= class_name %>.find(1) - process :destroy, 'id' => $base_id + process :destroy, 'id' => 1 assert_redirected_to :action => 'list<%= suffix %>' assert_raise(ActiveRecord::RecordNotFound) { - <%= singular_name %> = <%= class_name %>.find($base_id) + <%= singular_name %> = <%= class_name %>.find(1) } end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml index 068fd67472..e0d56d1122 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml @@ -10,7 +10,7 @@ <%% for <%= singular_name %> in @<%= plural_name %> %> <%% for column in <%= class_name %>.content_columns %> - <%%=h <%= singular_name %>[column.name] %> + <%%=h <%= singular_name %>.send(column.name) %> <%% end %> <%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %>.id %> <%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %>.id %> diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb index ba47fd79be..00b78ce645 100644 --- a/railties/lib/rails_generator/lookup.rb +++ b/railties/lib/rails_generator/lookup.rb @@ -4,24 +4,20 @@ class Object class << self # Lookup missing generators using const_missing. This allows any # generator to reference another without having to know its location: - # RubyGems, ~/.rails/generators, and RAILS_ROOT/script/generators all - # cooperate to get the job done. The greatest use of const_missing - # autoloading is to easily subclass existing generators. Example: - # class HorsebackGenerator < PostbackGenerator - # We don't know whether the postback generator is built in, installed - # as a gem, or in the user's home directory, and we shouldn't have to. - unless respond_to?(:pre_generator_const_missing) - alias_method :pre_generator_const_missing, :const_missing - - def const_missing(class_id) - if md = /(.+)Generator$/.match(class_id.to_s) - name = md.captures.first.demodulize.underscore - Rails::Generator::Base.lookup(name).klass - else - pre_generator_const_missing(class_id) - end + # RubyGems, ~/.rails/generators, and RAILS_ROOT/script/generators. + def lookup_missing_generator(class_id) + if md = /(.+)Generator$/.match(class_id.to_s) + name = md.captures.first.demodulize.underscore + Rails::Generator::Base.lookup(name).klass + else + const_missing_before_generators(class_id) end end + + unless respond_to?(:const_missing_before_generators) + alias_method :const_missing_before_generators, :const_missing + alias_method :const_missing, :lookup_missing_generator + end end end @@ -102,7 +98,7 @@ module Rails # 4. Builtins. Model, controller, mailer, scaffold. def use_component_sources! reset_sources - sources << PathSource.new(:app, "#{Object.const_get(:RAILS_ROOT)}/script/generators") if Object.const_defined?(:RAILS_ROOT) + sources << PathSource.new(:app, "#{::RAILS_ROOT}/script/generators") if defined? ::RAILS_ROOT sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") sources << GemSource.new if Object.const_defined?(:Gem) sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") diff --git a/railties/lib/rails_generator/options.rb b/railties/lib/rails_generator/options.rb index afe2d31625..54785413ef 100644 --- a/railties/lib/rails_generator/options.rb +++ b/railties/lib/rails_generator/options.rb @@ -1,8 +1,12 @@ require 'optparse' -require File.dirname(__FILE__) + '/../support/class_inheritable_attributes' +require File.dirname(__FILE__) + '/support/class_inheritable_attributes' module Rails module Generator + # Implement add_options! to add your options to the parser: + # def add_options!(opt) + # opt.on('-v', '--verbose') { |value| options[:verbose] = value } + # end module Options def self.append_features(base) super @@ -85,13 +89,14 @@ module Rails @option_parser = OptionParser.new do |opt| opt.banner = banner - add_options!(opt) + add_options!(opt) if respond_to?(:add_options!) add_general_options!(opt) opt.parse!(args) end + return args + ensure self.options = full_options(runtime_options) - args end # Raise a usage error. Override usage_message to provide a blurb @@ -109,14 +114,6 @@ module Rails "Usage: #{$0} [options]" end - # Override with a method that adds options to the parser. - # Added options should use the options hash. For example, - # def add_options!(opt) - # opt.on('-v', '--verbose') { |value| options[:verbose] = value } - # end - def add_options!(opt) - end - # Adds general options like -h and --quiet. Usually don't override. def add_general_options!(opt) opt.separator '' diff --git a/railties/lib/rails_generator/scripts.rb b/railties/lib/rails_generator/scripts.rb index 007980dcb5..f0b6b6f1ff 100644 --- a/railties/lib/rails_generator/scripts.rb +++ b/railties/lib/rails_generator/scripts.rb @@ -16,21 +16,23 @@ module Rails # or first remaining argument, and invokes the requested command. def run(args = [], runtime_options = {}) begin - parse!(args, runtime_options) - - # Generator name is the only required option. - unless options[:generator] - usage if args.empty? - options[:generator] ||= args.shift - end + parse!(args.dup, runtime_options) + rescue OptionParser::InvalidOption => e + # Don't cry, script. Generators want what you think is invalid. + end - # Look up generator instance and invoke command on it. - Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke! - rescue => e - puts e - puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace] - raise SystemExit + # Generator name is the only required option. + unless options[:generator] + usage if args.empty? + options[:generator] ||= args.shift end + + # Look up generator instance and invoke command on it. + Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke! + rescue => e + puts e + puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace] + raise SystemExit end protected diff --git a/railties/lib/rails_generator/scripts/destroy.rb b/railties/lib/rails_generator/scripts/destroy.rb index fd8469fbc7..628ec4de32 100644 --- a/railties/lib/rails_generator/scripts/destroy.rb +++ b/railties/lib/rails_generator/scripts/destroy.rb @@ -3,9 +3,5 @@ require File.dirname(__FILE__) + '/../scripts' module Rails::Generator::Scripts class Destroy < Base mandatory_options :command => :destroy - - protected - def add_options!(opt) - end end end diff --git a/railties/lib/rails_generator/scripts/generate.rb b/railties/lib/rails_generator/scripts/generate.rb index 329d6691df..1fe2f54ab3 100644 --- a/railties/lib/rails_generator/scripts/generate.rb +++ b/railties/lib/rails_generator/scripts/generate.rb @@ -3,9 +3,5 @@ require File.dirname(__FILE__) + '/../scripts' module Rails::Generator::Scripts class Generate < Base mandatory_options :command => :create - - protected - def add_options!(opt) - end end end diff --git a/railties/lib/rails_generator/scripts/update.rb b/railties/lib/rails_generator/scripts/update.rb index ad1ae8004a..53a9faa366 100644 --- a/railties/lib/rails_generator/scripts/update.rb +++ b/railties/lib/rails_generator/scripts/update.rb @@ -5,9 +5,6 @@ module Rails::Generator::Scripts mandatory_options :command => :update protected - def add_options!(opt) - end - def banner "Usage: #{$0} [options] scaffold" end diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index 3cb0db0a49..5814f87a06 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -27,14 +27,10 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet def do_GET(req, res) begin - unless handle_index(req, res) + unless handle_file(req, res) + REQUEST_MUTEX.lock unless handle_dispatch(req, res) - unless handle_file(req, res) - REQUEST_MUTEX.lock - unless handle_mapped(req, res) - raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." - end - end + raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." end end ensure @@ -44,20 +40,6 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet alias :do_POST :do_GET - def handle_index(req, res) - if req.request_uri.path == "/" - if @server_options[:index_controller] - res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/#{@server_options[:index_controller]}/" - else - res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/_doc/" - end - - return true - else - return false - end - end - def handle_file(req, res) begin @file_handler.send(:do_GET, req, res) @@ -70,22 +52,7 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet end end - def handle_mapped(req, res) - if mappings = DispatchServlet.parse_uri(req.request_uri.path) - query = mappings.collect { |pair| "#{pair.first}=#{pair.last}" }.join("&") - query << "&#{req.request_uri.query}" if req.request_uri.query - origin = req.request_uri.path + "?" + query - req.request_uri.path = "/dispatch.rb" - req.request_uri.query = query - handle_dispatch(req, res, origin) - else - return false - end - end - def handle_dispatch(req, res, origin = nil) - return false unless /^\/dispatch\.(?:cgi|rb|fcgi)$/.match(req.request_uri.path) - env = req.meta_vars.clone env["QUERY_STRING"] = req.request_uri.query env["REQUEST_URI"] = origin if origin @@ -120,35 +87,4 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet p err, err.backtrace return false end - - def self.parse_uri(path) - component, id = /([-_a-zA-Z0-9]+)/, /([0-9]+)/ - - case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/") - when %r{^/#{component}/?$} then - { :controller => $1, :action => "index" } - when %r{^/#{component}/#{component}$} then - { :controller => $1, :action => $2 } - when %r{^/#{component}/#{component}/#{id}$} then - { :controller => $1, :action => $2, :id => $3 } - - when %r{^/#{component}/#{component}/$} then - { :module => $1, :controller => $2, :action => "index" } - when %r{^/#{component}/#{component}/#{component}$} then - if DispatchServlet.modules(component).include?($1) - { :module => $1, :controller => $2, :action => $3 } - else - { :controller => $1, :action => $2, :id => $3 } - end - when %r{^/#{component}/#{component}/#{component}/#{id}$} then - { :module => $1, :controller => $2, :action => $3, :id => $4 } - else - false - end - end - - def self.modules(module_pattern = '[^.]+') - path = RAILS_ROOT + '/app/controllers' - Dir.entries(path).grep(/^#{module_pattern}$/).find_all {|e| File.directory?("#{path}/#{e}")} - end end -- cgit v1.2.3