From 582aa2ead58eacffca13e7efe94235958ee4db1b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 7 Nov 2008 16:23:22 -0500 Subject: Set up fixtures in app's test_help --- railties/lib/test_help.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 3cc61d7932..442ce3fadc 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -4,18 +4,19 @@ require_dependency 'application' # so fixtures are loaded to the right database silence_warnings { RAILS_ENV = "test" } -require 'test/unit' -require 'active_support/test_case' -require 'active_record/fixtures' -require 'action_controller/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" -ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path +require 'active_record/fixtures' +class ActiveSupport::TestCase + include ActiveRecord::TestFixtures +end + +ActiveSupport::TestCase.fixture_path = "#{RAILS_ROOT}/test/fixtures/" +ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path def create_fixtures(*table_names) - Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) + Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names) end begin -- cgit v1.2.3 From a0e7b99443cccbd01b0eefcd53b0e20878f54deb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 12 Nov 2008 11:32:36 -0800 Subject: Remove deprecated Gem.manage_gems --- railties/lib/tasks/framework.rake | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index 66ab78c3b2..5d1f8cf945 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -5,7 +5,6 @@ namespace :rails do deps = %w(actionpack activerecord actionmailer activesupport activeresource) require 'rubygems' require 'rubygems/gem_runner' - Gem.manage_gems rails = (version = ENV['VERSION']) ? Gem.cache.find_name('rails', "= #{version}").first : -- cgit v1.2.3 From b17eb65d00242ae10ac9ed97ef22d88fdd710533 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 12 Nov 2008 11:33:09 -0800 Subject: Move fixtures settings from AR::TestCase to railties test_help --- railties/lib/test_help.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 442ce3fadc..a7be514cf0 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -7,16 +7,22 @@ silence_warnings { RAILS_ENV = "test" } require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -require 'active_record/fixtures' -class ActiveSupport::TestCase - include ActiveRecord::TestFixtures -end +if defined?(ActiveRecord) + require 'active_record/test_case' + require 'active_record/fixtures' + + class ActiveSupport::TestCase + include ActiveRecord::TestFixtures + self.fixture_path = "#{RAILS_ROOT}/test/fixtures/" + self.use_instantiated_fixtures = false + self.use_transactional_fixtures = true + end -ActiveSupport::TestCase.fixture_path = "#{RAILS_ROOT}/test/fixtures/" -ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path + ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path -def create_fixtures(*table_names) - Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names) + def create_fixtures(*table_names, &block) + Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) + end end begin -- cgit v1.2.3 From 9a88ab64bb45ddb2bdcf80fab9203111d8f8abb4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 12 Nov 2008 11:33:09 -0800 Subject: Move fixtures settings from AR::TestCase to railties test_help --- railties/lib/test_help.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 3cc61d7932..367533cf0f 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -11,11 +11,22 @@ require 'action_controller/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" -ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path +if defined?(ActiveRecord) + require 'active_record/test_case' + require 'active_record/fixtures' -def create_fixtures(*table_names) - Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) + class ActiveSupport::TestCase + include ActiveRecord::TestFixtures + self.fixture_path = "#{RAILS_ROOT}/test/fixtures/" + self.use_instantiated_fixtures = false + self.use_transactional_fixtures = true + end + + ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path + + def create_fixtures(*table_names, &block) + Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) + end end begin -- cgit v1.2.3 From 334178722b8c33aba4acefe7f89e767a5660fc46 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 13 Nov 2008 21:06:11 -0800 Subject: Properly check silence_spec_warnings class variable [#1372 state:committed] Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/vendor_gem_source_index.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb index dc821693ac..5b7721f303 100644 --- a/railties/lib/rails/vendor_gem_source_index.rb +++ b/railties/lib/rails/vendor_gem_source_index.rb @@ -81,7 +81,7 @@ module Rails spec.files = files else $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+ - " Giving up.") unless @silence_spec_warnings + " Giving up.") unless @@silence_spec_warnings next end end @@ -137,4 +137,4 @@ module Rails end end -end \ No newline at end of file +end -- cgit v1.2.3 From ff4ccb8334e4f5b5bdccbd5dc6876b4e43d9565e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Nov 2008 12:01:26 +0100 Subject: Revert "Move fixtures settings from AR::TestCase to railties test_help" -- it broke all the tests! This reverts commit 9a88ab64bb45ddb2bdcf80fab9203111d8f8abb4. --- railties/lib/test_help.rb | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 367533cf0f..3cc61d7932 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -11,22 +11,11 @@ require 'action_controller/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -if defined?(ActiveRecord) - require 'active_record/test_case' - require 'active_record/fixtures' +Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" +ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path - class ActiveSupport::TestCase - include ActiveRecord::TestFixtures - self.fixture_path = "#{RAILS_ROOT}/test/fixtures/" - self.use_instantiated_fixtures = false - self.use_transactional_fixtures = true - end - - ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - - def create_fixtures(*table_names, &block) - Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) - end +def create_fixtures(*table_names) + Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) end begin -- cgit v1.2.3 From 61e43700b85de753b6254893d5365e04d3465b9a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Nov 2008 12:26:50 +0100 Subject: Prepare for RC2 --- railties/lib/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index a0986a2e05..bd835fba26 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -2,7 +2,7 @@ module Rails module VERSION #:nodoc: MAJOR = 2 MINOR = 2 - TINY = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From fcce1f17eaf9993b0210fe8e2a8117b61a1f0f69 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 17 Nov 2008 19:16:31 +0100 Subject: BACKWARDS INCOMPATIBLE: Renamed application.rb to application_controller.rb and removed all the special casing that was in place to support the former. You must do this rename in your own application when you upgrade to this version [DHH] --- .../lib/rails_generator/generators/applications/app/app_generator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') 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 32c320385d..8c9bc63fc6 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -47,7 +47,8 @@ class AppGenerator < Rails::Generator::Base m.file "README", "README" # Application - m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest } + m.template "helpers/application_controller.rb", "app/controllers/application_controller.rb", :assigns => { + :app_name => @app_name, :app_secret => md5.hexdigest } m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb" m.template "helpers/test_helper.rb", "test/test_helper.rb" m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb" -- cgit v1.2.3 From 5a4789e86adf73ba3757caa9111c3b5ad481b940 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 17 Nov 2008 15:18:01 -0800 Subject: Explicitly require test/unit so tests autorun --- railties/lib/test_help.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index a7be514cf0..daa5201663 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -4,6 +4,10 @@ require_dependency 'application' # so fixtures are loaded to the right database silence_warnings { RAILS_ENV = "test" } +require 'test/unit' +require 'active_support/test_case' +require 'active_controller/test_case' +require 'action_view/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -- cgit v1.2.3 From 8f71d6bcf621389ee8bb23a4a4d2a074906cdbfe Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 18 Nov 2008 08:28:26 +0530 Subject: Fix script/console --- railties/lib/console_with_helpers.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/console_with_helpers.rb b/railties/lib/console_with_helpers.rb index be453a6896..f9e8bf9cbf 100644 --- a/railties/lib/console_with_helpers.rb +++ b/railties/lib/console_with_helpers.rb @@ -16,8 +16,6 @@ def helper(*helper_names) end end -require_dependency 'application' - class << helper include_all_modules_from ActionView end -- cgit v1.2.3 From 3319fa69655744678e9458b4c585958f5d3956b1 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 18 Nov 2008 08:38:01 +0530 Subject: Dont require 'application' when running tests --- railties/lib/test_help.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index daa5201663..3ccbfebaf6 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -1,5 +1,3 @@ -require_dependency 'application' - # Make double-sure the RAILS_ENV is set to test, # so fixtures are loaded to the right database silence_warnings { RAILS_ENV = "test" } -- cgit v1.2.3 From d22fe41cf87d781ce1af264b37ba3eca762b74c3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 18 Nov 2008 08:40:38 +0530 Subject: Fix a typo in test helper --- railties/lib/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 3ccbfebaf6..b5c92c1790 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -4,7 +4,7 @@ silence_warnings { RAILS_ENV = "test" } require 'test/unit' require 'active_support/test_case' -require 'active_controller/test_case' +require 'action_controller/test_case' require 'action_view/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -- cgit v1.2.3 From 3c9beb3dab73013af83b90983f283b76625052b8 Mon Sep 17 00:00:00 2001 From: Eugene Bolshakov Date: Mon, 17 Nov 2008 21:55:56 -0600 Subject: Add helper test generators [#1199 state:resolved] Signed-off-by: Joshua Peek --- .../generators/components/controller/USAGE | 23 ++++++++++---------- .../components/controller/controller_generator.rb | 8 ++++++- .../components/controller/templates/helper_test.rb | 4 ++++ .../generators/components/helper/USAGE | 24 +++++++++++++++++++++ .../components/helper/helper_generator.rb | 25 ++++++++++++++++++++++ .../components/helper/templates/helper.rb | 2 ++ .../components/helper/templates/helper_test.rb | 4 ++++ .../generators/components/resource/USAGE | 4 ++-- .../components/resource/resource_generator.rb | 2 ++ .../components/resource/templates/helper_test.rb | 4 ++++ .../components/scaffold/scaffold_generator.rb | 2 ++ .../components/scaffold/templates/helper_test.rb | 4 ++++ railties/lib/tasks/testing.rake | 8 +++---- 13 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb create mode 100644 railties/lib/rails_generator/generators/components/helper/USAGE create mode 100644 railties/lib/rails_generator/generators/components/helper/helper_generator.rb create mode 100644 railties/lib/rails_generator/generators/components/helper/templates/helper.rb create mode 100644 railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb create mode 100644 railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb create mode 100644 railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/components/controller/USAGE b/railties/lib/rails_generator/generators/components/controller/USAGE index d4fae60c81..362872e84a 100644 --- a/railties/lib/rails_generator/generators/components/controller/USAGE +++ b/railties/lib/rails_generator/generators/components/controller/USAGE @@ -6,24 +6,25 @@ Description: path like 'parent_module/controller_name'. This generates a controller class in app/controllers, view templates in - app/views/controller_name, a helper class in app/helpers, and a functional - test suite in test/functional. + app/views/controller_name, a helper class in app/helpers, a functional + test suite in test/functional and a helper test suite in test/unit/helpers. Example: `./script/generate controller CreditCard open debit credit close` Credit card controller with URLs like /credit_card/debit. - Controller: app/controllers/credit_card_controller.rb - Views: app/views/credit_card/debit.html.erb [...] - Helper: app/helpers/credit_card_helper.rb - Test: test/functional/credit_card_controller_test.rb + Controller: app/controllers/credit_card_controller.rb + Functional Test: test/functional/credit_card_controller_test.rb + Views: app/views/credit_card/debit.html.erb [...] + Helper: app/helpers/credit_card_helper.rb + Helper Test: test/unit/helpers/credit_card_helper_test.rb Modules Example: `./script/generate controller 'admin/credit_card' suspend late_fee` Credit card admin controller with URLs /admin/credit_card/suspend. - Controller: app/controllers/admin/credit_card_controller.rb - Views: app/views/admin/credit_card/debit.html.erb [...] - Helper: app/helpers/admin/credit_card_helper.rb - Test: test/functional/admin/credit_card_controller_test.rb - + Controller: app/controllers/admin/credit_card_controller.rb + Functional Test: test/functional/admin/credit_card_controller_test.rb + Views: app/views/admin/credit_card/debit.html.erb [...] + Helper: app/helpers/admin/credit_card_helper.rb + Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb 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 77b2220d57..dc126e8a98 100644 --- a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb +++ b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb @@ -2,13 +2,14 @@ class ControllerGenerator < Rails::Generator::NamedBase def manifest record do |m| # Check for class naming collisions. - m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" + m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest" # 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) + m.directory File.join('test/unit/helpers', class_path) # Controller class, functional test, and helper class. m.template 'controller.rb', @@ -26,6 +27,11 @@ class ControllerGenerator < Rails::Generator::NamedBase class_path, "#{file_name}_helper.rb") + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + # View template for each action. actions.each do |action| path = File.join('app/views', class_path, file_name, "#{action}.html.erb") diff --git a/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb new file mode 100644 index 0000000000..591e40900e --- /dev/null +++ b/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/railties/lib/rails_generator/generators/components/helper/USAGE b/railties/lib/rails_generator/generators/components/helper/USAGE new file mode 100644 index 0000000000..ef27ca617e --- /dev/null +++ b/railties/lib/rails_generator/generators/components/helper/USAGE @@ -0,0 +1,24 @@ +Description: + Stubs out a new helper. Pass the helper name, either + CamelCased or under_scored. + + To create a helper within a module, specify the helper name as a + path like 'parent_module/helper_name'. + + This generates a helper class in app/helpers and a helper test + suite in test/unit/helpers. + +Example: + `./script/generate helper CreditCard` + + Credit card helper. + Helper: app/helpers/credit_card_helper.rb + Test: test/unit/helpers/credit_card_helper_test.rb + +Modules Example: + `./script/generate helper 'admin/credit_card'` + + Credit card admin helper. + Helper: app/helpers/admin/credit_card_helper.rb + Test: test/unit/helpers/admin/credit_card_helper_test.rb + diff --git a/railties/lib/rails_generator/generators/components/helper/helper_generator.rb b/railties/lib/rails_generator/generators/components/helper/helper_generator.rb new file mode 100644 index 0000000000..f7831f7c7a --- /dev/null +++ b/railties/lib/rails_generator/generators/components/helper/helper_generator.rb @@ -0,0 +1,25 @@ +class HelperGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_path, "#{class_name}Helper", "#{class_name}HelperTest" + + # Helper and helper test directories. + m.directory File.join('app/helpers', class_path) + m.directory File.join('test/unit/helpers', class_path) + + # Helper and helper test class. + + m.template 'helper.rb', + File.join('app/helpers', + class_path, + "#{file_name}_helper.rb") + + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + + end + end +end diff --git a/railties/lib/rails_generator/generators/components/helper/templates/helper.rb b/railties/lib/rails_generator/generators/components/helper/templates/helper.rb new file mode 100644 index 0000000000..3fe2ecdc74 --- /dev/null +++ b/railties/lib/rails_generator/generators/components/helper/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= class_name %>Helper +end diff --git a/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb new file mode 100644 index 0000000000..591e40900e --- /dev/null +++ b/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/railties/lib/rails_generator/generators/components/resource/USAGE b/railties/lib/rails_generator/generators/components/resource/USAGE index 83cc9d7654..e6043f1de1 100644 --- a/railties/lib/rails_generator/generators/components/resource/USAGE +++ b/railties/lib/rails_generator/generators/components/resource/USAGE @@ -11,8 +11,8 @@ Description: You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately. - This creates a model, controller, tests and fixtures for both, and the - corresponding map.resources declaration in config/routes.rb + This creates a model, controller, helper, tests and fixtures for all of them, + and the corresponding map.resources declaration in config/routes.rb Unlike the scaffold generator, the resource generator does not create views or add any methods to the generated controller. diff --git a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb b/railties/lib/rails_generator/generators/components/resource/resource_generator.rb index ea6dd65bde..4ee2fbff63 100644 --- a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb +++ b/railties/lib/rails_generator/generators/components/resource/resource_generator.rb @@ -40,6 +40,7 @@ class ResourceGenerator < Rails::Generator::NamedBase m.directory(File.join('app/views', controller_class_path, controller_file_name)) m.directory(File.join('test/functional', controller_class_path)) m.directory(File.join('test/unit', class_path)) + m.directory(File.join('test/unit/helpers', class_path)) m.dependency 'model', [name] + @args, :collision => :skip @@ -49,6 +50,7 @@ class ResourceGenerator < Rails::Generator::NamedBase m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) + m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) m.route_resources controller_file_name end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb new file mode 100644 index 0000000000..061f64a5e3 --- /dev/null +++ b/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= controller_class_name %>HelperTest < ActionView::TestCase +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 ff0381da2a..2a5edeedb6 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -47,6 +47,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase m.directory(File.join('app/views/layouts', controller_class_path)) m.directory(File.join('test/functional', controller_class_path)) m.directory(File.join('test/unit', class_path)) + m.directory(File.join('test/unit/helpers', class_path)) m.directory(File.join('public/stylesheets', class_path)) for action in scaffold_views @@ -66,6 +67,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) + m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) m.route_resources controller_file_name diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb new file mode 100644 index 0000000000..061f64a5e3 --- /dev/null +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= controller_class_name %>HelperTest < ActionView::TestCase +end diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake index 328bde7442..4242458672 100644 --- a/railties/lib/tasks/testing.rake +++ b/railties/lib/tasks/testing.rake @@ -7,7 +7,7 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) tests = [] source_dir = File.dirname(path).split("/") source_file = File.basename(path, '.rb') - + # Support subdirs in app/models and app/controllers modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path @@ -18,7 +18,7 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}" FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test) - + return tests end @@ -63,7 +63,7 @@ namespace :test do t.test_files = touched.uniq end Rake::Task['test:recent'].comment = "Test recent changes" - + Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t| def t.file_list if File.directory?(".svn") @@ -82,7 +82,7 @@ namespace :test do unit_tests.uniq + functional_tests.uniq end - + t.libs << 'test' t.verbose = true end -- cgit v1.2.3 From d9b92ee11b33fed5c7a94a91415fa846705f7dd3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 18 Nov 2008 14:23:13 +0100 Subject: Added config.i18n settings gatherer to config/environment, auto-loading of all locales in config/locales/*.rb,yml, and config/locales/en.yml as a sample locale [DHH] --- railties/lib/initializer.rb | 31 ++++++++++++++++++++++ .../generators/applications/app/app_generator.rb | 4 +++ 2 files changed, 35 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index e3a0e3bad1..3e97a17e0e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -147,7 +147,10 @@ module Rails initialize_dependency_mechanism initialize_whiny_nils initialize_temporary_session_directory + initialize_time_zone + initialize_i18n + initialize_framework_settings initialize_framework_views @@ -504,6 +507,18 @@ Run `rake gems:install` to install the missing gems. end end + # Set the i18n configuration from config.i18n but special-case for the load_path which should be + # appended to what's already set instead of overwritten. + def initialize_i18n + configuration.i18n.each do |setting, value| + if setting == :load_path + I18n.load_path += value + else + I18n.send("#{setting}=", value) + end + end + end + # Initializes framework-specific settings for each of the loaded frameworks # (Configuration#frameworks). The available settings map to the accessors # on each of the corresponding Base classes. @@ -732,6 +747,9 @@ Run `rake gems:install` to install the missing gems. # timezone to :utc. attr_accessor :time_zone + # Accessor for i18n settings. + attr_accessor :i18n + # Create a new Configuration instance, initialized with the default # values. def initialize @@ -755,6 +773,7 @@ Run `rake gems:install` to install the missing gems. self.database_configuration_file = default_database_configuration_file self.routes_configuration_file = default_routes_configuration_file self.gems = default_gems + self.i18n = default_i18n for framework in default_frameworks self.send("#{framework}=", Rails::OrderedOptions.new) @@ -967,6 +986,18 @@ Run `rake gems:install` to install the missing gems. def default_gems [] end + + def default_i18n + i18n = Rails::OrderedOptions.new + i18n.load_path = [] + + if File.exist?(File.join(RAILS_ROOT, 'config', 'locales')) + i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')] + i18n.load_path.flatten! + end + + i18n + end end end 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 8c9bc63fc6..d68c425871 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -65,6 +65,9 @@ class AppGenerator < Rails::Generator::Base m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" + # Locale + m.template "configs/locales/en.yml", "config/locales/en.yml" + # Environments m.file "environments/boot.rb", "config/boot.rb" m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret } @@ -143,6 +146,7 @@ class AppGenerator < Rails::Generator::Base app/views/layouts config/environments config/initializers + config/locales db doc lib -- cgit v1.2.3 From 45ba4ec626b79dda8534f13b3eb01524e0734781 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 17 Nov 2008 14:03:46 -0500 Subject: add vendor/ back to load paths; catch errors in constant loading Signed-off-by: David Heinemeier Hansson --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 3e97a17e0e..16abe62d1b 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -901,6 +901,7 @@ Run `rake gems:install` to install the missing gems. components config lib + vendor ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } paths.concat builtin_directories -- cgit v1.2.3 From 51a19ae2bf33e66b23ff5c91bf584b2efa9e669f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Nov 2008 14:12:38 +0100 Subject: Assume that the next version is going to be 2.3 for now --- railties/lib/rails/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index bd835fba26..9bb4b2a96d 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -1,8 +1,8 @@ module Rails module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 - TINY = 1 + MINOR = 3 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From baa8ee5eb1056d07c6623c37a57818317cd5bcc4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 4 Nov 2008 19:33:39 +0900 Subject: Require active_support/secure_random for Ruby 1.9. [#1326 state:committed] Signed-off-by: Jeremy Kemper --- .../lib/rails_generator/generators/applications/app/app_generator.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') 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 d68c425871..347ce6352c 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -1,5 +1,6 @@ require 'rbconfig' require 'digest/md5' +require 'active_support/secure_random' class AppGenerator < Rails::Generator::Base DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], -- cgit v1.2.3 From f42c77f927eb49b00e84d355e07de48723d03fcb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 22 Nov 2008 18:06:08 +0100 Subject: Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH] --- railties/lib/initializer.rb | 8 +++++ railties/lib/rails/backtrace_cleaner.rb | 34 ++++++++++++++++++++++ .../generators/applications/app/app_generator.rb | 7 +++-- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/backtrace_cleaner.rb (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 16abe62d1b..fcf6ea3feb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -39,6 +39,14 @@ module Rails nil end end + + def backtrace_cleaner + @@backtrace_cleaner ||= begin + # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded + require 'rails/backtrace_cleaner' + Rails::BacktraceCleaner.new + end + end def root if defined?(RAILS_ROOT) diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb new file mode 100644 index 0000000000..ffc5ef42aa --- /dev/null +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -0,0 +1,34 @@ +module Rails + class BacktraceCleaner < ActiveSupport::BacktraceCleaner + ERB_METHOD_SIG = /:in `_run_erb_.*/ + + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + RAILS_NOISE = %w( script/server ) + RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) + + ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + + + def initialize + super + add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + end + end + + + # For installing the BacktraceCleaner in the test/unit + module BacktraceFilterForTestUnit #:nodoc: + def self.included(klass) + klass.send :alias_method_chain, :filter_backtrace, :cleaning + end + + def filter_backtrace_with_cleaning(backtrace) + backtrace = filter_backtrace_without_cleaning(backtrace) + backtrace = backtrace.first.split("\n") if backtrace.size == 1 + Rails.backtrace_cleaner.clean(backtrace) + end + end +end \ No newline at end of file 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 347ce6352c..e52dcadd4d 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -62,9 +62,10 @@ class AppGenerator < Rails::Generator::Base m.template "configs/routes.rb", "config/routes.rb" # Initializers - m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" - m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" - m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" + m.template "configs/initializers/backtrace_silencers.rb", "config/initializers/backtrace_silencers.rb" + m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" + m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" + m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" # Locale m.template "configs/locales/en.yml", "config/locales/en.yml" -- cgit v1.2.3 From 2144c0f8ff9bdd3dceb085ddb1c4b8711ef329a4 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Sat, 22 Nov 2008 13:32:36 -0600 Subject: Add flush by ensure in script/runner because no flush in production mode [#803 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/commands/runner.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/runner.rb b/railties/lib/commands/runner.rb index 14159c3893..2411c3d270 100644 --- a/railties/lib/commands/runner.rb +++ b/railties/lib/commands/runner.rb @@ -38,11 +38,15 @@ RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) require RAILS_ROOT + '/config/environment' -if code_or_file.nil? - $stderr.puts "Run '#{$0} -h' for help." - exit 1 -elsif File.exist?(code_or_file) - eval(File.read(code_or_file), nil, code_or_file) -else - eval(code_or_file) +begin + if code_or_file.nil? + $stderr.puts "Run '#{$0} -h' for help." + exit 1 + elsif File.exist?(code_or_file) + eval(File.read(code_or_file), nil, code_or_file) + else + eval(code_or_file) + end +ensure + RAILS_DEFAULT_LOGGER.flush if RAILS_DEFAULT_LOGGER end -- cgit v1.2.3 From 0ecf2f6bdb7423516a18f45a65e1301cf8cd9c7d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 22 Nov 2008 14:00:58 -0600 Subject: Kill dead "new_mongrel" handler --- railties/lib/commands/server.rb | 4 +- railties/lib/commands/servers/new_mongrel.rb | 16 -- railties/lib/rails/mongrel_server/commands.rb | 342 -------------------------- railties/lib/rails/mongrel_server/handler.rb | 55 ----- 4 files changed, 2 insertions(+), 415 deletions(-) delete mode 100644 railties/lib/commands/servers/new_mongrel.rb delete mode 100644 railties/lib/rails/mongrel_server/commands.rb delete mode 100644 railties/lib/rails/mongrel_server/handler.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 15f417b5be..54628d8bb1 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -20,7 +20,7 @@ rescue Exception end server = case ARGV.first - when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin" + when "lighttpd", "mongrel", "webrick", "thin" ARGV.shift else if defined?(Mongrel) @@ -39,7 +39,7 @@ case server puts "=> Booting WEBrick..." when "lighttpd" puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)" - when "mongrel", "new_mongrel" + when "mongrel" puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)" when "thin" puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)" diff --git a/railties/lib/commands/servers/new_mongrel.rb b/railties/lib/commands/servers/new_mongrel.rb deleted file mode 100644 index 174dbf8a37..0000000000 --- a/railties/lib/commands/servers/new_mongrel.rb +++ /dev/null @@ -1,16 +0,0 @@ -unless defined?(Mongrel) - abort "PROBLEM: Mongrel is not available on your system (or not in your path)" -end - -require 'rails/mongrel_server/commands' - -GemPlugin::Manager.instance.load "rails::mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE - -case ARGV[0] ||= 'start' -when 'start', 'stop', 'restart' - ARGV[0] = "rails::mongrelserver::#{ARGV[0]}" -end - -if not Mongrel::Command::Registry.instance.run ARGV - exit 1 -end diff --git a/railties/lib/rails/mongrel_server/commands.rb b/railties/lib/rails/mongrel_server/commands.rb deleted file mode 100644 index d29b18712f..0000000000 --- a/railties/lib/rails/mongrel_server/commands.rb +++ /dev/null @@ -1,342 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'optparse' -require 'yaml' -require 'etc' - -require 'mongrel' -require 'rails/mongrel_server/handler' - -module Rails - module MongrelServer - def self.send_signal(signal, pid_file) - pid = open(pid_file).read.to_i - print "Sending #{signal} to Mongrel at PID #{pid}..." - begin - Process.kill(signal, pid) - rescue Errno::ESRCH - puts "Process does not exist. Not running." - end - - puts "Done." - end - - class RailsConfigurator < Mongrel::Configurator - def setup_mime_types - mime = {} - - if defaults[:mime_map] - Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}") - mime = load_mime_map(defaults[:mime_map], mime) - end - - mime.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) } - end - - def mount_rails(prefix) - ENV['RAILS_ENV'] = defaults[:environment] - ::RAILS_ENV.replace(defaults[:environment]) if defined?(::RAILS_ENV) - - env_location = "#{defaults[:cwd]}/config/environment" - require env_location - - ActionController::Base.relative_url_root = defaults[:prefix] - uri prefix, :handler => Rails::MongrelServer::RailsHandler.new - end - end - - class Start < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"], - ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false], - ['-p', '--port PORT', "Which port to bind to", :@port, 3000], - ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"], - ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"], - ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "tmp/pids/mongrel.pid"], - ['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024], - ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60], - ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0], - ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil], - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, RAILS_ROOT], - ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"], - ['-B', '--debug', "Enable debugging mode", :@debug, false], - ['-C', '--config PATH', "Use a config file", :@config_file, nil], - ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil], - ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil], - ['', '--user USER', "User to run as", :@user, nil], - ['', '--group GROUP', "Group to run as", :@group, nil], - ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil], - - ['-b', '--binding ADDR', "Address to bind to (deprecated, use -a)", :@address, "0.0.0.0"], - ['-u', '--debugger', "Enable debugging mode (deprecated, use -B)", :@debug, false] - ] - end - - def validate - if @config_file - valid_exists?(@config_file, "Config file not there: #@config_file") - return false unless @valid - @config_file = File.expand_path(@config_file) - load_config - return false unless @valid - end - - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - # Change there to start, then we'll have to come back after daemonize - Dir.chdir(@cwd) - - valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix - valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file" - valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file" - valid_dir? @docroot, "Path to docroot not valid: #@docroot" - valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map - valid_exists? @config_file, "Config file not there: #@config_file" if @config_file - valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate - valid_user? @user if @user - valid_group? @group if @group - - return @valid - end - - def run - if @generate - @generate = File.expand_path(@generate) - Mongrel.log(:error, "** Writing config to \"#@generate\".") - open(@generate, "w") {|f| f.write(settings.to_yaml) } - Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.") - exit 0 - end - - config = RailsConfigurator.new(settings) do - defaults[:log] = $stdout if defaults[:environment] == 'development' - - Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}") - - unless defaults[:daemon] - Mongrel.log("=> Call with -d to detach") - Mongrel.log("=> Ctrl-C to shutdown server") - start_debugger if defaults[:debug] - end - - if defaults[:daemon] - if File.exist? defaults[:pid_file] - Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.") - Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.") - exit 1 - end - - daemonize - - Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.") - Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file - end - - Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log") - - listener do - prefix = defaults[:prefix] || '/' - - if defaults[:debug] - Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.") - debug(prefix) - end - - setup_mime_types - dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false) - dir_handler.passthrough_missing_files = true - - unless defaults[:environment] == 'production' - Mongrel.log("Mounting DirHandler at #{prefix}...") - uri prefix, :handler => dir_handler - end - - - Mongrel.log("Starting Rails with #{defaults[:environment]} environment...") - Mongrel.log("Mounting Rails at #{prefix}...") - mount_rails(prefix) - Mongrel.log("Rails loaded.") - - - Mongrel.log("Loading any Rails specific GemPlugins" ) - load_plugins - - if defaults[:config_script] - Mongrel.log("Loading #{defaults[:config_script]} external config script") - run_config(defaults[:config_script]) - end - - setup_signals - end - end - - config.run - Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}") - - if config.defaults[:daemon] - config.write_pid_file - else - Mongrel.log("Use CTRL-C to stop.") - tail "log/#{config.defaults[:environment]}.log" - end - - config.join - - if config.needs_restart - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ - cmd = "ruby #{__FILE__} start #{original_args.join(' ')}" - Mongrel.log("Restarting with arguments: #{cmd}") - config.stop(false, true) - config.remove_pid_file - - if config.defaults[:daemon] - system cmd - else - Mongrel.log(:error, "Can't restart unless in daemon mode.") - exit 1 - end - else - Mongrel.log("Win32 does not support restarts. Exiting.") - end - end - end - - def load_config - settings = {} - begin - settings = YAML.load_file(@config_file) - ensure - Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon] - end - - settings[:includes] ||= ["mongrel"] - - # Config file settings will override command line settings - settings.each do |key, value| - key = key.to_s - if config_keys.include?(key) - key = 'address' if key == 'host' - self.instance_variable_set("@#{key}", value) - else - failure "Unknown configuration setting: #{key}" - @valid = false - end - end - end - - def config_keys - @config_keys ||= - %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix) - end - - def settings - config_keys.inject({}) do |hash, key| - value = self.instance_variable_get("@#{key}") - key = 'host' if key == 'address' - hash[key.to_sym] ||= value - hash - end - end - - def start_debugger - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - Mongrel.log("=> Debugger enabled") - rescue Exception - Mongrel.log(:error, "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'") - exit - end - - def tail(log_file) - cursor = File.size(log_file) - last_checked = Time.now - tail_thread = Thread.new do - File.open(log_file, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end - tail_thread - end - end - - class Stop < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."], - ['-f', '--force', "Force the shutdown (kill -9).", :@force, false], - ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"], - ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - if @force - @wait.to_i.times do |waiting| - exit(0) if not File.exist? @pid_file - sleep 1 - end - - Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file - else - Mongrel::send_signal("TERM", @pid_file) - end - end - end - - - class Restart < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'], - ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - MongrelServer::send_signal("USR2", @pid_file) - end - end - end -end diff --git a/railties/lib/rails/mongrel_server/handler.rb b/railties/lib/rails/mongrel_server/handler.rb deleted file mode 100644 index a19eca7259..0000000000 --- a/railties/lib/rails/mongrel_server/handler.rb +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'mongrel' -require 'cgi' -require 'action_controller/dispatcher' - - -module Rails - module MongrelServer - # Implements a handler that can run Rails and serve files out of the - # Rails application's public directory. This lets you run your Rails - # application with Mongrel during development and testing, then use it - # also in production behind a server that's better at serving the - # static files. - # - # The RailsHandler takes a mime_map parameter which is a simple suffix=mimetype - # mapping that it should add to the list of valid mime types. - # - # It also supports page caching directly and will try to resolve a request - # in the following order: - # - # * If the requested exact PATH_INFO exists as a file then serve it. - # * If it exists at PATH_INFO+".html" exists then serve that. - # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispatch to have Rails go. - # - # This means that if you are using page caching it will actually work with Mongrel - # and you should see a decent speed boost (but not as fast as if you use a static - # server like Apache or Litespeed). - class RailsHandler < Mongrel::HttpHandler - # Construct a Mongrel::CGIWrapper and dispatch. - def process(request, response) - return if response.socket.closed? - - cgi = Mongrel::CGIWrapper.new(request, response) - cgi.handler = self - # We don't want the output to be really final until we're out of the lock - cgi.default_really_final = false - - ActionController::Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body) - - # This finalizes the output using the proper HttpResponse way - cgi.out("text/html",true) {""} - rescue Errno::EPIPE - response.socket.close - rescue Object => rails_error - STDERR.puts "#{Time.now.httpdate}: Error dispatching #{rails_error.inspect}" - STDERR.puts rails_error.backtrace.join("\n") - end - end - end -end -- cgit v1.2.3 From 40c6a8b9701f4e137799cecfc72c64aca7b4004b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 22 Nov 2008 14:10:50 -0600 Subject: Drop lighttpd support from script/server --- railties/lib/commands/server.rb | 6 +- railties/lib/commands/servers/lighttpd.rb | 94 ------------------------------- 2 files changed, 1 insertion(+), 99 deletions(-) delete mode 100644 railties/lib/commands/servers/lighttpd.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 54628d8bb1..1d33d7afba 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -20,15 +20,13 @@ rescue Exception end server = case ARGV.first - when "lighttpd", "mongrel", "webrick", "thin" + when "mongrel", "webrick", "thin" ARGV.shift else if defined?(Mongrel) "mongrel" elsif defined?(Thin) "thin" - elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI) - "lighttpd" else "webrick" end @@ -37,8 +35,6 @@ end case server when "webrick" puts "=> Booting WEBrick..." - when "lighttpd" - puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)" when "mongrel" puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)" when "thin" diff --git a/railties/lib/commands/servers/lighttpd.rb b/railties/lib/commands/servers/lighttpd.rb deleted file mode 100644 index c9d13e86f3..0000000000 --- a/railties/lib/commands/servers/lighttpd.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' - -unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? - puts "PROBLEM: Lighttpd is not available on your system (or not in your path)" - exit 1 -end - -unless defined?(FCGI) - puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system" - exit 1 -end - -require 'initializer' -configuration = Rails::Initializer.run(:initialize_logger).configuration -default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath - -require 'optparse' - -detach = false -command_line_port = nil - -ARGV.options do |opt| - opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port } - opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path } - opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 } - opt.on('-d', '-d', 'Call with -d to detach') { detach = true; puts "=> Configuration in config/lighttpd.conf" } - opt.parse! -end - -unless File.exist?(config_file) - if config_file != default_config_file - puts "=> #{config_file} not found." - exit 1 - end - - require 'fileutils' - - source = File.expand_path(File.join(File.dirname(__FILE__), - "..", "..", "..", "configs", "lighttpd.conf")) - puts "=> #{config_file} not found, copying from #{source}" - - FileUtils.cp(source, config_file) -end - -# open the config/lighttpd.conf file and add the current user defined port setting to it -if command_line_port - File.open(config_file, 'r+') do |config| - lines = config.readlines - - lines.each do |line| - line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}") - end - - config.rewind - config.print(lines) - config.truncate(config.pos) - end -end - -config = IO.read(config_file) -default_port, default_ip = 3000, '0.0.0.0' -port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port -ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip -puts "=> Rails #{Rails.version} application starting on http://#{ip || default_ip}:#{port || default_port}" - -tail_thread = nil - -if !detach - puts "=> Call with -d to detach" - puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" - detach = false - tail_thread = tail(configuration.log_path) -end - -trap(:INT) { exit } - -begin - `rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around - `lighttpd #{!detach ? "-D " : ""}-f #{config_file}` -ensure - unless detach - tail_thread.kill if tail_thread - puts 'Exiting' - - # Ensure FCGI processes are reaped - silence_stream(STDOUT) do - ARGV.replace ['-a', 'kill'] - require 'commands/process/reaper' - end - - `rake tmp:sockets:clear` # Remove sockets on clean shutdown - end -end -- cgit v1.2.3 From 708f4c3ae6a41a46ab36a05ea4e126392b81511b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 22 Nov 2008 14:48:32 -0600 Subject: Switch script/server to use rack processor --- railties/lib/commands/server.rb | 124 +++++++++++++++++++++++-------- railties/lib/commands/servers/base.rb | 31 -------- railties/lib/commands/servers/mongrel.rb | 69 ----------------- railties/lib/commands/servers/thin.rb | 25 ------- railties/lib/commands/servers/webrick.rb | 66 ---------------- 5 files changed, 95 insertions(+), 220 deletions(-) delete mode 100644 railties/lib/commands/servers/base.rb delete mode 100644 railties/lib/commands/servers/mongrel.rb delete mode 100644 railties/lib/commands/servers/thin.rb delete mode 100644 railties/lib/commands/servers/webrick.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 1d33d7afba..f9a444e208 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -1,45 +1,111 @@ require 'active_support' require 'fileutils' +require 'action_controller/vendor/rack' +require 'optparse' +# TODO: Push Thin adapter upstream so we don't need worry about requiring it begin - require_library_or_gem 'fcgi' + require_library_or_gem 'thin' rescue Exception - # FCGI not available + # Thin not available end -begin - require_library_or_gem 'mongrel' -rescue Exception - # Mongrel not available +options = { + :Port => 3000, + :Host => "0.0.0.0", + :environment => (ENV['RAILS_ENV'] || "development").dup, + :config => RAILS_ROOT + "/config.ru", + :detach => false, + :debugger => false +} + +ARGV.clone.options do |opts| + opts.on("-p", "--port=port", Integer, + "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } + opts.on("-b", "--binding=ip", String, + "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v } + opts.on("-c", "--config=file", String, + "Use custom rackup configuration file") { |v| options[:config] = v } + opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true } + opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true } + opts.on("-e", "--environment=name", String, + "Specifies the environment to run this server under (test/development/production).", + "Default: development") { |v| options[:environment] = v } + + opts.separator "" + + opts.on("-h", "--help", "Show this help message.") { puts opts; exit } + + opts.parse! end -begin - require_library_or_gem 'thin' -rescue Exception - # Thin not available +server = Rack::Handler.get(ARGV.first) rescue nil +unless server + begin + server = Rack::Handler::Mongrel + rescue LoadError => e + server = Rack::Handler::WEBrick + end end -server = case ARGV.first - when "mongrel", "webrick", "thin" - ARGV.shift - else - if defined?(Mongrel) - "mongrel" - elsif defined?(Thin) - "thin" - else - "webrick" +puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" +puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}" + +%w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) +end + +if options[:detach] + Process.daemon + pid = "#{RAILS_ROOT}/tmp/pids/server.pid" + File.open(pid, 'w'){ |f| f.write(Process.pid) } + at_exit { File.delete(pid) if File.exist?(pid) } +end + +ENV["RAILS_ENV"] = options[:environment] +RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) +require RAILS_ROOT + "/config/environment" + +if File.exist?(options[:config]) + config = options[:config] + if config =~ /\.ru$/ + cfgfile = File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse!($1.split(/\s+/)) end + app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) + else + require config + app = Object.const_get(File.basename(config, '.rb').capitalize) + end +else + app = Rack::Builder.new { + use Rails::Rack::Logger + use Rails::Rack::Static + run ActionController::Dispatcher.new + }.to_app end -case server - when "webrick" - puts "=> Booting WEBrick..." - when "mongrel" - puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)" - when "thin" - puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)" +if options[:debugger] + begin + require_library_or_gem 'ruby-debug' + Debugger.start + Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) + puts "=> Debugger enabled" + rescue Exception + puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" + exit + end end -%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) } -require "commands/servers/#{server}" +puts "=> Call with -d to detach" + +trap(:INT) { exit } + +puts "=> Ctrl-C to shutdown server" + +begin + server.run(app, options.merge(:AccessLog => [])) +ensure + puts 'Exiting' +end diff --git a/railties/lib/commands/servers/base.rb b/railties/lib/commands/servers/base.rb deleted file mode 100644 index 23be169a8d..0000000000 --- a/railties/lib/commands/servers/base.rb +++ /dev/null @@ -1,31 +0,0 @@ -def tail(log_file) - cursor = File.size(log_file) - last_checked = Time.now - tail_thread = Thread.new do - File.open(log_file, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end - tail_thread -end - -def start_debugger - begin - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - puts "=> Debugger enabled" - rescue Exception - puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" - exit - end -end \ No newline at end of file diff --git a/railties/lib/commands/servers/mongrel.rb b/railties/lib/commands/servers/mongrel.rb deleted file mode 100644 index 7bb110f63a..0000000000 --- a/railties/lib/commands/servers/mongrel.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' - -unless defined?(Mongrel) - puts "PROBLEM: Mongrel is not available on your system (or not in your path)" - exit 1 -end - -require 'optparse' - -OPTIONS = { - :port => 3000, - :ip => "0.0.0.0", - :environment => (ENV['RAILS_ENV'] || "development").dup, - :detach => false, - :debugger => false -} - -ARGV.clone.options do |opts| - opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v } - opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v } - opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true } - opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true } - opts.on("-e", "--environment=name", String, - "Specifies the environment to run this server under (test/development/production).", - "Default: development") { |v| OPTIONS[:environment] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -puts "=> Rails #{Rails.version} application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" - -parameters = [ - "start", - "-p", OPTIONS[:port].to_s, - "-a", OPTIONS[:ip].to_s, - "-e", OPTIONS[:environment], - "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid" -] - -if OPTIONS[:detach] - `mongrel_rails #{parameters.join(" ")} -d` -else - ENV["RAILS_ENV"] = OPTIONS[:environment] - RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV) - - start_debugger if OPTIONS[:debugger] - - puts "=> Call with -d to detach" - puts "=> Ctrl-C to shutdown server" - - log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath - open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log - tail_thread = tail(log) - - trap(:INT) { exit } - - begin - silence_warnings { ARGV = parameters } - load("mongrel_rails") - ensure - tail_thread.kill if tail_thread - puts 'Exiting' - end -end \ No newline at end of file diff --git a/railties/lib/commands/servers/thin.rb b/railties/lib/commands/servers/thin.rb deleted file mode 100644 index 833469cab1..0000000000 --- a/railties/lib/commands/servers/thin.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' -require 'thin' - - -options = ARGV.clone -options.insert(0,'start') unless Thin::Runner.commands.include?(options[0]) - -thin = Thin::Runner.new(options) - -puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}" -puts "=> Ctrl-C to shutdown server" - -log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath -open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log -tail_thread = tail(log) -trap(:INT) { exit } - -begin - thin.run! -ensure - tail_thread.kill if tail_thread - puts 'Exiting' -end - diff --git a/railties/lib/commands/servers/webrick.rb b/railties/lib/commands/servers/webrick.rb deleted file mode 100644 index 18c8897cc8..0000000000 --- a/railties/lib/commands/servers/webrick.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'webrick' -require 'optparse' -require 'commands/servers/base' - -OPTIONS = { - :port => 3000, - :ip => "0.0.0.0", - :environment => (ENV['RAILS_ENV'] || "development").dup, - :server_root => File.expand_path(RAILS_ROOT + "/public/"), - :server_type => WEBrick::SimpleServer, - :charset => "UTF-8", - :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes, - :debugger => false - -} - -ARGV.options do |opts| - script_name = File.basename($0) - opts.banner = "Usage: ruby #{script_name} [options]" - - opts.separator "" - - opts.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", - "Default: 3000") { |v| OPTIONS[:port] = v } - opts.on("-b", "--binding=ip", String, - "Binds Rails to the specified ip.", - "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v } - opts.on("-e", "--environment=name", String, - "Specifies the environment to run this server under (test/development/production).", - "Default: development") { |v| OPTIONS[:environment] = v } - opts.on("-m", "--mime-types=filename", String, - "Specifies an Apache style mime.types configuration file to be used for mime types", - "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) } - - opts.on("-d", "--daemon", - "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)." - ) { OPTIONS[:server_type] = WEBrick::Daemon } - - opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true } - - opts.on("-c", "--charset=charset", String, - "Set default charset for output.", - "Default: UTF-8") { |v| OPTIONS[:charset] = v } - - opts.separator "" - - opts.on("-h", "--help", - "Show this help message.") { puts opts; exit } - - opts.parse! -end - -start_debugger if OPTIONS[:debugger] - -ENV["RAILS_ENV"] = OPTIONS[:environment] -RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV) - -require RAILS_ROOT + "/config/environment" -require 'webrick_server' - -OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT) - -puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" -puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer -DispatchServlet.dispatch(OPTIONS) -- cgit v1.2.3 From 9e08a3bb1d47f79b6953056e72eee58e86d83ead Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 23 Nov 2008 13:39:30 +0100 Subject: Added rake rails:update:application_controller to renamed application.rb to application_controller.rb -- included in rake rails:update so upgrading to 2.3 will automatically trigger it [#1439 state:committed] (kastner) --- railties/lib/tasks/framework.rake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index 5d1f8cf945..4cf174b15b 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -78,7 +78,7 @@ namespace :rails do end desc "Update both configs, scripts and public/javascripts from Rails" - task :update => [ "update:scripts", "update:javascripts", "update:configs" ] + task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:application_controller" ] namespace :update do desc "Add new scripts to the application script/ directory" @@ -114,5 +114,15 @@ namespace :rails do require 'railties_path' FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb') end + + desc "Rename application.rb to application_controller.rb" + task :application_controller do + old_style = RAILS_ROOT + '/app/controllers/application.rb' + new_style = RAILS_ROOT + '/app/controllers/application_controller.rb' + if File.exists?(old_style) && !File.exists?(new_style) + FileUtils.mv(old_style, new_style) + puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" + end + end end end -- cgit v1.2.3 From d75a2345015046e08f8191748f0e246e1b9f9703 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 23 Nov 2008 15:15:05 -0600 Subject: simplify console with helpers --- railties/lib/console_with_helpers.rb | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/console_with_helpers.rb b/railties/lib/console_with_helpers.rb index f9e8bf9cbf..039db667c4 100644 --- a/railties/lib/console_with_helpers.rb +++ b/railties/lib/console_with_helpers.rb @@ -1,24 +1,5 @@ -class Module - def include_all_modules_from(parent_module) - parent_module.constants.each do |const| - mod = parent_module.const_get(const) - if mod.class == Module - send(:include, mod) - include_all_modules_from(mod) - end - end - end -end - -def helper(*helper_names) - returning @helper_proxy ||= Object.new do |helper| - helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize } - end -end - -class << helper - include_all_modules_from ActionView +def helper + @helper ||= ApplicationController.helpers end @controller = ApplicationController.new -helper :application rescue nil -- cgit v1.2.3 From 1f48c09094610cbf26ec1e93d9bf978b2ae86fa8 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Mon, 24 Nov 2008 11:25:28 +0100 Subject: Accept a prefix argument to filter_backtrace_with_cleaning [#1456 state:committed] Add a prefix argument to filter_backtrace_with_cleaning so it has the same arity as test/unit's filter_backtrace. Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/backtrace_cleaner.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index ffc5ef42aa..88df0ebbda 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -1,14 +1,13 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ - + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) RAILS_NOISE = %w( script/server ) RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE - def initialize super @@ -18,15 +17,14 @@ module Rails end end - # For installing the BacktraceCleaner in the test/unit module BacktraceFilterForTestUnit #:nodoc: def self.included(klass) klass.send :alias_method_chain, :filter_backtrace, :cleaning end - - def filter_backtrace_with_cleaning(backtrace) - backtrace = filter_backtrace_without_cleaning(backtrace) + + def filter_backtrace_with_cleaning(backtrace, prefix=nil) + backtrace = filter_backtrace_without_cleaning(backtrace, prefix) backtrace = backtrace.first.split("\n") if backtrace.size == 1 Rails.backtrace_cleaner.clean(backtrace) end -- cgit v1.2.3 From 42b4407e35e8634370fb95dc6786d4fd0c0e6afa Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 24 Nov 2008 15:43:47 +0100 Subject: Strip out the ./ part of the test path so the backtrace align perfectly --- railties/lib/rails/backtrace_cleaner.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 88df0ebbda..82537d962f 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -13,6 +13,7 @@ module Rails super add_filter { |line| line.sub(RAILS_ROOT, '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_filter { |line| line.sub('./', '/') } # for tests add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } end end -- cgit v1.2.3 From 5ffd1e0c02e605158efc08f3cbb6aebb79978553 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 24 Nov 2008 09:58:52 -0600 Subject: Ensure integration test is load in script/console [#1452 state:resolved] --- railties/lib/console_app.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index 88e7962b43..96bf3117c8 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -1,4 +1,5 @@ -require 'action_controller/integration' +require 'active_support/test_case' +require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) -- cgit v1.2.3 From 5b5730cc6e9194fb5f67fe79d2c7849e200ba6ed Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Mon, 24 Nov 2008 19:22:04 +0100 Subject: Don't generate public/dispatch.cgi/fcgi/rb files by default. Signed-off-by: Pratik Naik --- .../generators/applications/app/app_generator.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'railties/lib') 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 e52dcadd4d..892dba20b0 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -10,7 +10,7 @@ class AppGenerator < Rails::Generator::Base DEFAULT_DATABASE = 'sqlite3' default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), - :shebang => DEFAULT_SHEBANG, :freeze => false + :shebang => DEFAULT_SHEBANG, :with_dispatches => false, :freeze => false mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." def initialize(runtime_args, runtime_options = {}) @@ -83,9 +83,11 @@ class AppGenerator < Rails::Generator::Base end # Dispatches - m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options - m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options - m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options + if options[:with_dispatches] + m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options + m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options + m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options + end # HTML files %w(404 422 500 index).each do |file| @@ -129,6 +131,10 @@ class AppGenerator < Rails::Generator::Base "Preconfigure for selected database (options: #{DATABASES.join('/')}).", "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v } + opt.on("-D", "--with-dispatches", + "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton", + "Default: false") { |v| options[:with_dispatches] = v } + opt.on("-f", "--freeze", "Freeze Rails in vendor/rails from the gems generating the skeleton", "Default: false") { |v| options[:freeze] = v } -- cgit v1.2.3 From b7568e77d79cba9202b961cbe2a822b8b6b34bb0 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 24 Nov 2008 19:35:09 +0100 Subject: Fix typo in 5b5730cc6e9194fb5f67fe79d2c7849e200ba6ed --- .../rails_generator/generators/applications/app/app_generator.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib') 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 892dba20b0..32383d2bbd 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -10,7 +10,7 @@ class AppGenerator < Rails::Generator::Base DEFAULT_DATABASE = 'sqlite3' default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), - :shebang => DEFAULT_SHEBANG, :with_dispatches => false, :freeze => false + :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." def initialize(runtime_args, runtime_options = {}) @@ -83,7 +83,7 @@ class AppGenerator < Rails::Generator::Base end # Dispatches - if options[:with_dispatches] + if options[:with_dispatchers] m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options @@ -131,9 +131,9 @@ class AppGenerator < Rails::Generator::Base "Preconfigure for selected database (options: #{DATABASES.join('/')}).", "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v } - opt.on("-D", "--with-dispatches", + opt.on("-D", "--with-dispatchers", "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton", - "Default: false") { |v| options[:with_dispatches] = v } + "Default: false") { |v| options[:with_dispatchers] = v } opt.on("-f", "--freeze", "Freeze Rails in vendor/rails from the gems generating the skeleton", -- cgit v1.2.3 From 1cbdd53bd383e7d1dc34cad50c22ff5a330bbf91 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 24 Nov 2008 19:50:09 +0100 Subject: Add a rake task to generate dispatchers : rake rails:generate_dispatchers --- railties/lib/tasks/framework.rake | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index 4cf174b15b..df080e94ac 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -124,5 +124,13 @@ namespace :rails do puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" end end + + desc "Generate dispatcher files in RAILS_ROOT/public" + task :generate_dispatchers do + require 'railties_path' + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.fcgi', RAILS_ROOT + '/public/dispatch.fcgi') + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.rb') + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.cgi') + end end end -- cgit v1.2.3 From d01f75b1f091c37d14ece70cbe5f52f20f25d64c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 18:10:23 -0800 Subject: Initializer#env relies on StringInquirer autoload. Style fixes. --- railties/lib/initializer.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index fcf6ea3feb..82b7b604ae 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -57,10 +57,7 @@ module Rails end def env - @_env ||= begin - require 'active_support/string_inquirer' - ActiveSupport::StringInquirer.new(RAILS_ENV) - end + @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) end def cache @@ -263,7 +260,7 @@ module Rails def require_frameworks configuration.frameworks.each { |framework| require(framework.to_s) } rescue LoadError => e - # re-raise because Mongrel would swallow it + # Re-raise as RuntimeError because Mongrel would swallow LoadError. raise e.to_s end @@ -869,10 +866,10 @@ Run `rake gems:install` to install the missing gems. def framework_paths paths = %w(railties railties/lib activesupport/lib) - paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view + paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view) [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| - paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework + paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework) end paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } -- cgit v1.2.3 From 104f3a57768602289299b3be0fab5b1ed21d7653 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 18:43:04 -0800 Subject: Add config.preload_frameworks to load all frameworks at startup. Default to false so Rails autoloads itself as it's used. --- railties/lib/initializer.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 82b7b604ae..0f74f9ff88 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -136,6 +136,7 @@ module Rails add_gem_load_paths require_frameworks + preload_frameworks set_autoload_paths add_plugin_load_paths load_environment @@ -264,6 +265,19 @@ module Rails raise e.to_s end + # Preload all frameworks specified by the Configuration#frameworks. + # Used by Passenger to ensure everything's loaded before forking and + # to avoid autoload race conditions in JRuby. + def preload_frameworks + if configuration.preload_frameworks + configuration.frameworks.each do |framework| + # String#classify and #constantize aren't available yet. + toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }) + toplevel.load_all! + end + end + end + # Add the load paths used by support functions such as the info controller def add_support_load_paths end @@ -602,6 +616,9 @@ Run `rake gems:install` to install the missing gems. # A stub for setting options on ActiveSupport. attr_accessor :active_support + # Whether to preload all frameworks at startup. + attr_accessor :preload_frameworks + # Whether or not classes should be cached (set to false if you want # application classes to be reloaded on each request) attr_accessor :cache_classes @@ -768,6 +785,7 @@ Run `rake gems:install` to install the missing gems. self.log_level = default_log_level self.view_path = default_view_path self.controller_paths = default_controller_paths + self.preload_frameworks = default_preload_frameworks self.cache_classes = default_cache_classes self.dependency_loading = default_dependency_loading self.whiny_nils = default_whiny_nils @@ -810,6 +828,7 @@ Run `rake gems:install` to install the missing gems. # multiple database connections. Also disables automatic dependency loading # after boot def threadsafe! + self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false self.action_controller.allow_concurrency = true @@ -955,6 +974,10 @@ Run `rake gems:install` to install the missing gems. true end + def default_preload_frameworks + false + end + def default_cache_classes true end -- cgit v1.2.3 From 36dcfcf126b7e7ba33ebe0d7148c9023e7494464 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 18:48:00 -0800 Subject: Really remove components. --- railties/lib/initializer.rb | 6 +----- railties/lib/tasks/statistics.rake | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0f74f9ff88..038288dc88 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -624,7 +624,7 @@ Run `rake gems:install` to install the missing gems. attr_accessor :cache_classes # The list of paths that should be searched for controllers. (Defaults - # to app/controllers and components.) + # to app/controllers.) attr_accessor :controller_paths # The path to the database configuration file to use. (Defaults to @@ -912,9 +912,6 @@ Run `rake gems:install` to install the missing gems. # Add the app's controller directory paths.concat(Dir["#{root_path}/app/controllers/"]) - # Then components subdirectories. - paths.concat(Dir["#{root_path}/components/[_a-z]*"]) - # Followed by the standard includes. paths.concat %w( app @@ -922,7 +919,6 @@ Run `rake gems:install` to install the missing gems. app/controllers app/helpers app/services - components config lib vendor diff --git a/railties/lib/tasks/statistics.rake b/railties/lib/tasks/statistics.rake index dbd0773194..5ab27a0f62 100644 --- a/railties/lib/tasks/statistics.rake +++ b/railties/lib/tasks/statistics.rake @@ -4,7 +4,6 @@ STATS_DIRECTORIES = [ %w(Models app/models), %w(Libraries lib/), %w(APIs app/apis), - %w(Components components), %w(Integration\ tests test/integration), %w(Functional\ tests test/functional), %w(Unit\ tests test/unit) -- cgit v1.2.3 From ce50ca1baf29f2edc829011ffc247e68ebd995c3 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 22:39:11 -0800 Subject: Explicitly require AS::Deprecation for the SecretKeyGenerator. Bring in ActiveSupport::TestCase for its tests. --- railties/lib/rails_generator/secret_key_generator.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/secret_key_generator.rb b/railties/lib/rails_generator/secret_key_generator.rb index 553811d35d..7dd495a2f5 100644 --- a/railties/lib/rails_generator/secret_key_generator.rb +++ b/railties/lib/rails_generator/secret_key_generator.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + module Rails # A class for creating random secret keys. This class will do its best to create a # random secret key that's as secure as possible, using whatever methods are -- cgit v1.2.3 From e126e1aac07d353e10fe9871fc3fc3f040cc8911 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 25 Nov 2008 13:26:38 -0600 Subject: don't try to require vendored rack in script/server --- railties/lib/commands/server.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index f9a444e208..f61c48567f 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -1,6 +1,7 @@ require 'active_support' +require 'action_controller' + require 'fileutils' -require 'action_controller/vendor/rack' require 'optparse' # TODO: Push Thin adapter upstream so we don't need worry about requiring it -- cgit v1.2.3 From c80fe1093deeb57eee8df11d3c4120158634cb81 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 25 Nov 2008 14:48:09 -0600 Subject: Move debugger into middleware --- railties/lib/commands/server.rb | 13 +------------ railties/lib/rails/rack.rb | 1 + railties/lib/rails/rack/debugger.rb | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 railties/lib/rails/rack/debugger.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index f61c48567f..a4bb52592f 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -83,22 +83,11 @@ else app = Rack::Builder.new { use Rails::Rack::Logger use Rails::Rack::Static + use Rails::Rack::Debugger if options[:debugger] run ActionController::Dispatcher.new }.to_app end -if options[:debugger] - begin - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - puts "=> Debugger enabled" - rescue Exception - puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" - exit - end -end - puts "=> Call with -d to detach" trap(:INT) { exit } diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index b4f32c2d95..90535674e9 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,5 +1,6 @@ module Rails module Rack + autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :Static, "rails/rack/static" end diff --git a/railties/lib/rails/rack/debugger.rb b/railties/lib/rails/rack/debugger.rb new file mode 100644 index 0000000000..aa2711c616 --- /dev/null +++ b/railties/lib/rails/rack/debugger.rb @@ -0,0 +1,21 @@ +module Rails + module Rack + class Debugger + def initialize(app) + @app = app + + require_library_or_gem 'ruby-debug' + ::Debugger.start + ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings) + puts "=> Debugger enabled" + rescue Exception + puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" + exit + end + + def call(env) + @app.call(env) + end + end + end +end -- cgit v1.2.3 From 63d8f56774dcb1ea601928c3eb6c119d359fae10 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 14:41:20 +0100 Subject: Added app/[models|controllers|helpers] to the load path for plugins that has an app directory (go engines ;)) [DHH] --- railties/lib/rails/plugin.rb | 25 ++++++++++++++++++++++--- railties/lib/rails/plugin/loader.rb | 10 +++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 4d983843af..3b9e7dec2d 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -28,13 +28,17 @@ module Rails end def valid? - File.directory?(directory) && (has_lib_directory? || has_init_file?) + File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?) end # Returns a list of paths this plugin wishes to make available in $LOAD_PATH. def load_paths report_nonexistant_or_empty_plugin! unless valid? - has_lib_directory? ? [lib_path] : [] + + returning [] do |load_paths| + load_paths << lib_path if has_lib_directory? + load_paths << app_paths if has_app_directory? + end.flatten end # Evaluates a plugin's init.rb file. @@ -68,7 +72,16 @@ module Rails def report_nonexistant_or_empty_plugin! raise LoadError, "Can not find the plugin named: #{name}" - end + end + + + def app_paths + [ + File.join(directory, 'app', 'models'), + File.join(directory, 'app', 'controllers'), + File.join(directory, 'app', 'helpers') + ] + end def lib_path File.join(directory, 'lib') @@ -86,6 +99,11 @@ module Rails File.file?(gem_init_path) ? gem_init_path : classic_init_path end + + def has_app_directory? + File.directory?(File.join(directory, 'app')) + end + def has_lib_directory? File.directory?(lib_path) end @@ -94,6 +112,7 @@ module Rails File.file?(init_path) end + def evaluate_init_rb(initializer) if has_init_file? silence_warnings do diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 948d497007..8d7eac53c5 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -33,6 +33,7 @@ module Rails plugin.load(initializer) register_plugin_as_loaded(plugin) end + ensure_all_registered_plugins_are_loaded! end @@ -45,12 +46,15 @@ module Rails plugins.each do |plugin| plugin.load_paths.each do |path| $LOAD_PATH.insert(application_lib_index + 1, path) - ActiveSupport::Dependencies.load_paths << path + + ActiveSupport::Dependencies.load_paths << path + unless Rails.configuration.reload_plugins? ActiveSupport::Dependencies.load_once_paths << path end end end + $LOAD_PATH.uniq! end @@ -59,9 +63,9 @@ module Rails # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins - configuration.plugin_locators.map { |locator| + configuration.plugin_locators.map do |locator| locator.new(initializer).plugins - }.flatten + end.flatten # TODO: sorting based on config.plugins end -- cgit v1.2.3 From 4999d52e08a02ebba344f6c318f0af4b5b18f0e5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 20:03:25 +0100 Subject: Added that config/routes.rb files in engine plugins are automatically loaded (and reloaded when they change in dev mode) [DHH] --- railties/lib/initializer.rb | 9 +++++++-- railties/lib/rails/plugin.rb | 23 +++++++++++++++++++++-- railties/lib/rails/plugin/loader.rb | 17 ++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 038288dc88..b0abf3379c 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -486,8 +486,13 @@ Run `rake gems:install` to install the missing gems. # loading module used to lazily load controllers (Configuration#controller_paths). def initialize_routing return unless configuration.frameworks.include?(:action_controller) - ActionController::Routing.controller_paths = configuration.controller_paths - ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file + + ActionController::Routing.controller_paths = configuration.controller_paths + plugin_loader.controller_paths + + ([ configuration.routes_configuration_file ] + plugin_loader.routing_files).each do |routing_file| + ActionController::Routing::Routes.add_configuration_file(routing_file) + end + ActionController::Routing::Routes.reload end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 3b9e7dec2d..2b1e877e2b 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -40,7 +40,7 @@ module Rails load_paths << app_paths if has_app_directory? end.flatten end - + # Evaluates a plugin's init.rb file. def load(initializer) return if loaded? @@ -60,7 +60,26 @@ module Rails def about @about ||= load_about_information end + + # Engines are plugins with an app/ directory. + def engine? + has_app_directory? + end + # Returns true if the engine ships with a routing file + def routed? + File.exist?(routing_file) + end + + def controller_path + File.join(directory, 'app', 'controllers') + end + + def routing_file + File.join(directory, 'config', 'routes.rb') + end + + private def load_about_information about_yml_path = File.join(@directory, "about.yml") @@ -82,7 +101,7 @@ module Rails File.join(directory, 'app', 'helpers') ] end - + def lib_path File.join(directory, 'lib') end diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 8d7eac53c5..ba3f67d1d0 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -22,6 +22,11 @@ module Rails @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) } end + # Returns the plugins that are in engine-form (have an app/ directory) + def engines + @engines ||= plugins.select(&:engine?) + end + # Returns all the plugins that could be found by the current locators. def all_plugins @all_plugins ||= locate_plugins @@ -56,7 +61,17 @@ module Rails end $LOAD_PATH.uniq! - end + end + + # Returns an array of all the controller paths found inside engine-type plugins. + def controller_paths + engines.collect(&:controller_path) + end + + def routing_files + engines.select(&:routed?).collect(&:routing_file) + end + protected -- cgit v1.2.3 From 3cc9d1c5ad1639283b43ee2b6099cb4f3b19bf23 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 20:30:21 +0100 Subject: Let all plugins not just engines have a config/routes.rb file --- railties/lib/rails/plugin/loader.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index ba3f67d1d0..f08d9b74e2 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -68,8 +68,9 @@ module Rails engines.collect(&:controller_path) end + # Returns an array of routing.rb files from all the plugins that include config/routes.rb def routing_files - engines.select(&:routed?).collect(&:routing_file) + plugins.select(&:routed?).collect(&:routing_file) end -- cgit v1.2.3 From 4d910b033379727e5e7355590c50c72fc75e56db Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 26 Nov 2008 20:54:47 -0600 Subject: Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache. --- railties/lib/initializer.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b0abf3379c..f282cff2de 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -372,9 +372,10 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + if configuration.cache_classes + ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + end end end -- cgit v1.2.3 From f2ee056873b84f8917e72d87181e1a9f5f653342 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 18:59:24 +0100 Subject: Added view path support for engines [DHH] --- railties/lib/initializer.rb | 8 ++------ railties/lib/rails/plugin.rb | 11 ++++++----- railties/lib/rails/plugin/loader.rb | 34 ++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 21 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b0abf3379c..0c06d1bf21 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -487,12 +487,8 @@ Run `rake gems:install` to install the missing gems. def initialize_routing return unless configuration.frameworks.include?(:action_controller) - ActionController::Routing.controller_paths = configuration.controller_paths + plugin_loader.controller_paths - - ([ configuration.routes_configuration_file ] + plugin_loader.routing_files).each do |routing_file| - ActionController::Routing::Routes.add_configuration_file(routing_file) - end - + ActionController::Routing.controller_paths += configuration.controller_paths + ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file) ActionController::Routing::Routes.reload end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 2b1e877e2b..4901abe808 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -71,6 +71,11 @@ module Rails File.exist?(routing_file) end + + def view_path + File.join(directory, 'app', 'views') + end + def controller_path File.join(directory, 'app', 'controllers') end @@ -95,11 +100,7 @@ module Rails def app_paths - [ - File.join(directory, 'app', 'models'), - File.join(directory, 'app', 'controllers'), - File.join(directory, 'app', 'helpers') - ] + [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ] end def lib_path diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index f08d9b74e2..be81bdf4fa 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -39,6 +39,8 @@ module Rails register_plugin_as_loaded(plugin) end + configure_engines + ensure_all_registered_plugins_are_loaded! end @@ -63,19 +65,31 @@ module Rails $LOAD_PATH.uniq! end - # Returns an array of all the controller paths found inside engine-type plugins. - def controller_paths - engines.collect(&:controller_path) - end - - # Returns an array of routing.rb files from all the plugins that include config/routes.rb - def routing_files - plugins.select(&:routed?).collect(&:routing_file) - end - protected + def configure_engines + if engines.any? + add_engine_routing_configurations + add_engine_controller_paths + add_engine_view_paths + end + end + def add_engine_routing_configurations + engines.select(&:routed?).collect(&:routing_file).each do |routing_file| + ActionController::Routing::Routes.add_configuration_file(routing_file) + end + end + + def add_engine_controller_paths + ActionController::Routing.controller_paths += engines.collect(&:controller_path) + end + + def add_engine_view_paths + # reverse it such that the last engine can overwrite view paths from the first, like with routes + ActionController::Base.view_paths += ActionView::PathSet.new(engines.collect(&:view_path).reverse) + end + # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins -- cgit v1.2.3 From 5fa0457542b0ff541d0a80ff8c3561eec8e35959 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 21:04:24 +0100 Subject: Revert "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading. This reverts commit 4d910b033379727e5e7355590c50c72fc75e56db. --- railties/lib/initializer.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a69898e2c5..0c06d1bf21 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -372,10 +372,9 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) - end + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes + ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) end end -- cgit v1.2.3 From 9fc23745f1511d8d97433828d9ca87970994d138 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 28 Nov 2008 11:18:28 -0600 Subject: Reinstate "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading." --- railties/lib/initializer.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0c06d1bf21..a69898e2c5 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -372,9 +372,10 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + if configuration.cache_classes + ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + end end end -- cgit v1.2.3 From 34905673a3018edeff71aafeceb64e487304d31d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 21:04:24 +0100 Subject: Revert "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading. This reverts commit 4d910b033379727e5e7355590c50c72fc75e56db. --- railties/lib/initializer.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a69898e2c5..0c06d1bf21 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -372,10 +372,9 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) - end + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes + ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) end end -- cgit v1.2.3 From 1e8f9634f65e1076deba3e20cca3d032ec12e026 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 29 Nov 2008 10:45:52 +0100 Subject: Include Rack in the server noise --- railties/lib/rails/backtrace_cleaner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 82537d962f..d8626aaf14 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -3,11 +3,11 @@ module Rails ERB_METHOD_SIG = /:in `_run_erb_.*/ VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) - MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/rack ) RAILS_NOISE = %w( script/server ) RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) - ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE def initialize super -- cgit v1.2.3 From fdfcdf467387c4db3d79c1f46eadbb55a88ef814 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 29 Nov 2008 10:57:36 +0100 Subject: Enhanced Rails.root to take parameters that'll be join with the root, like Rails.root('app', 'controllers') => File.join(Rails.root, 'app', 'controllers') [#1482 state:committed] (Damian Janowski) --- railties/lib/initializer.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0c06d1bf21..5baaf81403 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -48,12 +48,8 @@ module Rails end end - def root - if defined?(RAILS_ROOT) - RAILS_ROOT - else - nil - end + def root(*args) + File.join(RAILS_ROOT, *args.compact) if defined?(RAILS_ROOT) end def env -- cgit v1.2.3 From cfb2126726f34baedfab971785ad7ff19a7f54ce Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 29 Nov 2008 20:06:49 -0800 Subject: Load app initializers by path relative to Rails.root --- railties/lib/initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 8e8bcf21fe..b645ac3da2 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -564,7 +564,7 @@ Run `rake gems:install` to install the missing gems. def load_application_initializers if gems_dependencies_loaded Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer| - load(initializer) + load initializer.sub(/^#{Regexp.escape(configuration.root_path)}\//, '') end end end -- cgit v1.2.3 From 471f0240189fcdd2067621d51427dc09565fdc6a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 30 Nov 2008 14:58:42 -0600 Subject: Me loves me some whitespace --- railties/lib/initializer.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b645ac3da2..ef0c335478 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -513,10 +513,15 @@ Run `rake gems:install` to install the missing gems. def initialize_time_zone if configuration.time_zone zone_default = Time.__send__(:get_zone, configuration.time_zone) + unless zone_default - raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.} + raise \ + 'Value assigned to config.time_zone not recognized.' + + 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.' end + Time.zone_default = zone_default + if configuration.frameworks.include?(:active_record) ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.default_timezone = :utc -- cgit v1.2.3 From c5f461d7b0b8f5ee0021c78a80525c0594864c68 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 30 Nov 2008 15:52:50 -0600 Subject: Cleanup the app generator --- .../generators/applications/app/app_generator.rb | 338 ++++++++++++--------- 1 file changed, 196 insertions(+), 142 deletions(-) (limited to 'railties/lib') 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 32383d2bbd..5435b2aeb3 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -3,115 +3,37 @@ require 'digest/md5' require 'active_support/secure_random' class AppGenerator < Rails::Generator::Base - DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], - Config::CONFIG['ruby_install_name']) + DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db) + DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db ) DEFAULT_DATABASE = 'sqlite3' + mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false - mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." + def initialize(runtime_args, runtime_options = {}) super + usage if args.empty? usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db])) + @destination_root = args.shift @app_name = File.basename(File.expand_path(@destination_root)) end def manifest - # Use /usr/bin/env if no special shebang was specified - script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] } - dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } - - # duplicate CGI::Session#generate_unique_id - md5 = Digest::MD5.new - now = Time.now - md5 << now.to_s - md5 << String(now.usec) - md5 << String(rand(0)) - md5 << String($$) - md5 << @app_name - - # Do our best to generate a secure secret key for CookieStore - secret = ActiveSupport::SecureRandom.hex(64) - record do |m| - # Root directory and all subdirectories. - m.directory '' - BASEDIRS.each { |path| m.directory path } - - # Root - m.file "fresh_rakefile", "Rakefile" - m.file "README", "README" - - # Application - m.template "helpers/application_controller.rb", "app/controllers/application_controller.rb", :assigns => { - :app_name => @app_name, :app_secret => md5.hexdigest } - m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb" - m.template "helpers/test_helper.rb", "test/test_helper.rb" - m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb" - - # database.yml and routes.rb - m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { - :app_name => @app_name, - :socket => options[:db] == "mysql" ? mysql_socket_location : nil - } - m.template "configs/routes.rb", "config/routes.rb" - - # Initializers - m.template "configs/initializers/backtrace_silencers.rb", "config/initializers/backtrace_silencers.rb" - m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" - m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" - m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" - - # Locale - m.template "configs/locales/en.yml", "config/locales/en.yml" - - # Environments - m.file "environments/boot.rb", "config/boot.rb" - m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret } - m.file "environments/production.rb", "config/environments/production.rb" - m.file "environments/development.rb", "config/environments/development.rb" - m.file "environments/test.rb", "config/environments/test.rb" - - # Scripts - %w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| - m.file "bin/#{file}", "script/#{file}", script_options - end - - # Dispatches - if options[:with_dispatchers] - m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options - m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options - m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options - end - - # HTML files - %w(404 422 500 index).each do |file| - m.template "html/#{file}.html", "public/#{file}.html" - end - - m.template "html/favicon.ico", "public/favicon.ico" - m.template "html/robots.txt", "public/robots.txt" - m.file "html/images/rails.png", "public/images/rails.png" - - # Javascripts - m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js" - m.file "html/javascripts/effects.js", "public/javascripts/effects.js" - m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js" - m.file "html/javascripts/controls.js", "public/javascripts/controls.js" - m.file "html/javascripts/application.js", "public/javascripts/application.js" - - # Docs - m.file "doc/README_FOR_APP", "doc/README_FOR_APP" - - # Logs - %w(server production development test).each { |file| - m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666 - } + create_directories(m) + create_root_files(m) + create_app_files(m) + create_config_files(m) + create_script_files(m) + create_test_files(m) + create_public_files(m) + create_documentation_file(m) + create_log_files(m) end end @@ -140,53 +62,185 @@ class AppGenerator < Rails::Generator::Base "Default: false") { |v| options[:freeze] = v } end + + private + def create_directories(m) + m.directory '' + + # Intermediate directories are automatically created so don't sweat their absence here. + %w( + app/controllers + app/helpers + app/models + app/views/layouts + config/environments + config/initializers + config/locales + db + doc + lib + lib/tasks + log + public/images + public/javascripts + public/stylesheets + script/performance + script/process + test/fixtures + test/functional + test/integration + test/performance + test/unit + vendor + vendor/plugins + tmp/sessions + tmp/sockets + tmp/cache + tmp/pids + ).each { |path| m.directory(path) } + end + + def create_root_files(m) + m.file "fresh_rakefile", "Rakefile" + m.file "README", "README" + end + + def create_app_files(m) + m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb" + m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb" + end + + def create_config_files(m) + create_database_configuration_file(m) + create_routes_file(m) + create_locale_file(m) + create_initializer_files(m) + create_environment_files(m) + end + + def create_documentation_file(m) + m.file "doc/README_FOR_APP", "doc/README_FOR_APP" + end + + def create_log_files(m) + %w( server production development test ).each do |file| + m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666 + end + end + + def create_public_files(m) + create_dispatch_files(m) + create_error_files(m) + create_welcome_file(m) + create_browser_convention_files(m) + create_rails_image(m) + create_javascript_files(m) + end + + def create_script_files(m) + %w( + about console dbconsole destroy generate performance/benchmarker performance/profiler + performance/request process/reaper process/spawner process/inspector runner server plugin + ).each do |file| + m.file "bin/#{file}", "script/#{file}", { + :chmod => 0755, + :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] + } + end + end + + def create_test_files(m) + m.file "helpers/test_helper.rb", "test/test_helper.rb" + m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb" + end + + + def create_database_configuration_file(m) + m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { + :app_name => @app_name, + :socket => options[:db] == "mysql" ? mysql_socket_location : nil } + end + + def create_routes_file(m) + m.file "configs/routes.rb", "config/routes.rb" + end + + def create_initializer_files(m) + %w( + backtrace_silencers + inflections + mime_types + new_rails_defaults + ).each do |initializer| + m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb" + end + + m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb", + :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) } + end + + def create_locale_file(m) + m.file "configs/locales/en.yml", "config/locales/en.yml" + end + + def create_environment_files(m) + m.template "environments/environment.rb", "config/environment.rb", + :assigns => { :freeze => options[:freeze] } + + m.file "environments/boot.rb", "config/boot.rb" + m.file "environments/production.rb", "config/environments/production.rb" + m.file "environments/development.rb", "config/environments/development.rb" + m.file "environments/test.rb", "config/environments/test.rb" + end + + + def create_dispatch_files(m) + if options[:with_dispatchers] + dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } + + m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options + m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options + m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options + end + end + + def create_error_files(m) + %w( 404 422 500 ).each do |file| + m.file "html/#{file}.html", "public/#{file}.html" + end + end + + def create_welcome_file(m) + m.file 'html/index.html', 'public/index.html' + end + + def create_browser_convention_files(m) + m.file "html/favicon.ico", "public/favicon.ico" + m.file "html/robots.txt", "public/robots.txt" + end + + def create_rails_image(m) + m.file "html/images/rails.png", "public/images/rails.png" + end + + def create_javascript_files(m) + %w( prototype effects dragdrop controls application ).each do |javascript| + m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js" + end + end + + def mysql_socket_location - MYSQL_SOCKET_LOCATIONS.find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ - end - - - # Installation skeleton. Intermediate directories are automatically - # created so don't sweat their absence here. - BASEDIRS = %w( - app/controllers - app/helpers - app/models - app/views/layouts - config/environments - config/initializers - config/locales - db - doc - lib - lib/tasks - log - public/images - public/javascripts - public/stylesheets - script/performance - script/process - test/fixtures - test/functional - test/integration - test/performance - test/unit - vendor - vendor/plugins - tmp/sessions - tmp/sockets - tmp/cache - tmp/pids - ) - - MYSQL_SOCKET_LOCATIONS = [ - "/tmp/mysql.sock", # default - "/var/run/mysqld/mysqld.sock", # debian/gentoo - "/var/tmp/mysql.sock", # freebsd - "/var/lib/mysql/mysql.sock", # fedora - "/opt/local/lib/mysql/mysql.sock", # fedora - "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql - "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 - "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 - "/opt/lampp/var/mysql/mysql.sock" # xampp for linux - ] -end + [ + "/tmp/mysql.sock", # default + "/var/run/mysqld/mysqld.sock", # debian/gentoo + "/var/tmp/mysql.sock", # freebsd + "/var/lib/mysql/mysql.sock", # fedora + "/opt/local/lib/mysql/mysql.sock", # fedora + "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql + "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 + "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 + "/opt/lampp/var/mysql/mysql.sock" # xampp for linux + ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ + end +end \ No newline at end of file -- cgit v1.2.3 From be140e8c6be966349c6fa35a87f84d5a73995b9a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 30 Nov 2008 15:59:30 -0600 Subject: Changed Rails.root to return a Pathname object (allows for Rails.root.join("app", "controllers") => "#{RAILS_ROOT}/app/controllers") [#1482] --- railties/lib/initializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index ef0c335478..a134c68a50 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -48,8 +48,8 @@ module Rails end end - def root(*args) - File.join(RAILS_ROOT, *args.compact) if defined?(RAILS_ROOT) + def root + Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT) end def env -- cgit v1.2.3 From 3b3c0507e2f67a0f64dc04b396c1d13411ab5890 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 30 Nov 2008 16:23:20 -0600 Subject: Extracted the process scripts (inspector, reaper, spawner) into the plugin irs_process_scripts [DHH] --- railties/lib/commands/process/inspector.rb | 68 ------- railties/lib/commands/process/reaper.rb | 149 -------------- railties/lib/commands/process/spawner.rb | 219 --------------------- railties/lib/commands/process/spinner.rb | 57 ------ .../generators/applications/app/app_generator.rb | 5 +- 5 files changed, 2 insertions(+), 496 deletions(-) delete mode 100644 railties/lib/commands/process/inspector.rb delete mode 100644 railties/lib/commands/process/reaper.rb delete mode 100644 railties/lib/commands/process/spawner.rb delete mode 100644 railties/lib/commands/process/spinner.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/process/inspector.rb b/railties/lib/commands/process/inspector.rb deleted file mode 100644 index 8a6437e715..0000000000 --- a/railties/lib/commands/process/inspector.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'optparse' - -if RUBY_PLATFORM =~ /(:?mswin|mingw)/ then abort("Inspector is only for Unix") end - -OPTIONS = { - :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'), - :pattern => "dispatch.*.pid", - :ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s" -} - -class Inspector - def self.inspect(pid_path, pattern) - new(pid_path, pattern).inspect - end - - def initialize(pid_path, pattern) - @pid_path, @pattern = pid_path, pattern - end - - def inspect - header = `#{OPTIONS[:ps] % 1}`.split("\n")[0] + "\n" - lines = pids.collect { |pid| `#{OPTIONS[:ps] % pid}`.split("\n")[1] } - - puts(header + lines.join("\n")) - end - - private - def pids - pid_files.collect do |pid_file| - File.read(pid_file).to_i - end - end - - def pid_files - Dir.glob(@pid_path + "/" + @pattern) - end -end - - -ARGV.options do |opts| - opts.banner = "Usage: inspector [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - Displays system information about Rails dispatchers (or other processes that use pid files) through - the ps command. - - Examples: - inspector # default ps on all tmp/pids/dispatch.*.pid files - inspector -s 'ps -o user,start,majflt,pcpu,vsz -p %s' # custom ps, %s is where the pid is interleaved - EOF - - opts.on(" Options:") - - opts.on("-s", "--ps=command", "default: #{OPTIONS[:ps]}", String) { |v| OPTIONS[:ps] = v } - opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String) { |v| OPTIONS[:pid_path] = v } - opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -Inspector.inspect(OPTIONS[:pid_path], OPTIONS[:pattern]) diff --git a/railties/lib/commands/process/reaper.rb b/railties/lib/commands/process/reaper.rb deleted file mode 100644 index 95175d41e0..0000000000 --- a/railties/lib/commands/process/reaper.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'optparse' -require 'net/http' -require 'uri' - -if RUBY_PLATFORM =~ /(:?mswin|mingw)/ then abort("Reaper is only for Unix") end - -class Killer - class << self - # Searches for all processes matching the given keywords, and then invokes - # a specific action on each of them. This is useful for (e.g.) reloading a - # set of processes: - # - # Killer.process(:reload, "/tmp/pids", "dispatcher.*.pid") - def process(action, pid_path, pattern, keyword) - new(pid_path, pattern, keyword).process(action) - end - - # Forces the (rails) application to reload by sending a +HUP+ signal to the - # process. - def reload(pid) - `kill -s HUP #{pid}` - end - - # Force the (rails) application to restart by sending a +USR2+ signal to the - # process. - def restart(pid) - `kill -s USR2 #{pid}` - end - - # Forces the (rails) application to gracefully terminate by sending a - # +TERM+ signal to the process. - def graceful(pid) - `kill -s TERM #{pid}` - end - - # Forces the (rails) application to terminate immediately by sending a -9 - # signal to the process. - def kill(pid) - `kill -9 #{pid}` - end - - # Send a +USR1+ signal to the process. - def usr1(pid) - `kill -s USR1 #{pid}` - end - end - - def initialize(pid_path, pattern, keyword=nil) - @pid_path, @pattern, @keyword = pid_path, pattern, keyword - end - - def process(action) - pids = find_processes - - if pids.empty? - warn "Couldn't find any pid file in '#{@pid_path}' matching '#{@pattern}'" - warn "(also looked for processes matching #{@keyword.inspect})" if @keyword - else - pids.each do |pid| - puts "#{action.capitalize}ing #{pid}" - self.class.send(action, pid) - end - - delete_pid_files if terminating?(action) - end - end - - private - def terminating?(action) - [ "kill", "graceful" ].include?(action) - end - - def find_processes - files = pid_files - if files.empty? - find_processes_via_grep - else - files.collect { |pid_file| File.read(pid_file).to_i } - end - end - - def find_processes_via_grep - lines = `ps axww -o 'pid command' | grep #{@keyword}`.split(/\n/). - reject { |line| line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/ } - lines.map { |line| line[/^\s*(\d+)/, 1].to_i } - end - - def delete_pid_files - pid_files.each { |pid_file| File.delete(pid_file) } - end - - def pid_files - Dir.glob(@pid_path + "/" + @pattern) - end -end - - -OPTIONS = { - :action => "restart", - :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'), - :pattern => "dispatch.[0-9]*.pid", - :dispatcher => File.expand_path("#{RAILS_ROOT}/public/dispatch.fcgi") -} - -ARGV.options do |opts| - opts.banner = "Usage: reaper [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The reaper is used to restart, reload, gracefully exit, and forcefully exit processes - running a Rails Dispatcher (or any other process responding to the same signals). This - is commonly done when a new version of the application is available, so the existing - processes can be updated to use the latest code. - - It uses pid files to work on the processes and by default assume them to be located - in RAILS_ROOT/tmp/pids. - - The reaper actions are: - - * restart : Restarts the application by reloading both application and framework code - * reload : Only reloads the application, but not the framework (like the development environment) - * graceful: Marks all of the processes for exit after the next request - * kill : Forcefully exists all processes regardless of whether they're currently serving a request - - Restart is the most common and default action. - - Examples: - reaper # restarts the default dispatchers - reaper -a reload # reload the default dispatchers - reaper -a kill -r *.pid # kill all processes that keep pids in tmp/pids - EOF - - opts.on(" Options:") - - opts.on("-a", "--action=name", "reload|graceful|kill (default: #{OPTIONS[:action]})", String) { |v| OPTIONS[:action] = v } - opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String) { |v| OPTIONS[:pid_path] = v } - opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v } - opts.on("-d", "--dispatcher=path", "DEPRECATED. default: #{OPTIONS[:dispatcher]}", String) { |v| OPTIONS[:dispatcher] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -Killer.process(OPTIONS[:action], OPTIONS[:pid_path], OPTIONS[:pattern], OPTIONS[:dispatcher]) diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb deleted file mode 100644 index 8bf47abb75..0000000000 --- a/railties/lib/commands/process/spawner.rb +++ /dev/null @@ -1,219 +0,0 @@ -require 'active_support' -require 'optparse' -require 'socket' -require 'fileutils' - -def daemonize #:nodoc: - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - Dir.chdir "/" # Release old working directory. - File.umask 0000 # Ensure sensible umask. Adjust as needed. - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. -end - -class Spawner - def self.record_pid(name = "#{OPTIONS[:process]}.spawner", id = Process.pid) - FileUtils.mkdir_p(OPTIONS[:pids]) - File.open(File.expand_path(OPTIONS[:pids] + "/#{name}.pid"), "w+") { |f| f.write(id) } - end - - def self.spawn_all - OPTIONS[:instances].times do |i| - port = OPTIONS[:port] + i - print "Checking if something is already running on #{OPTIONS[:address]}:#{port}..." - - begin - srv = TCPServer.new(OPTIONS[:address], port) - srv.close - srv = nil - - puts "NO" - puts "Starting dispatcher on port: #{OPTIONS[:address]}:#{port}" - - FileUtils.mkdir_p(OPTIONS[:pids]) - spawn(port) - rescue - puts "YES" - end - end - end -end - -class FcgiSpawner < Spawner - def self.spawn(port) - cmd = "#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port} -P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid" - cmd << " -a #{OPTIONS[:address]}" if can_bind_to_custom_address? - system(cmd) - end - - def self.can_bind_to_custom_address? - @@can_bind_to_custom_address ||= /^\s-a\s/.match `#{OPTIONS[:spawner]} -h` - end -end - -class MongrelSpawner < Spawner - def self.spawn(port) - cmd = - "mongrel_rails start -d " + - "-a #{OPTIONS[:address]} " + - "-p #{port} " + - "-P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid " + - "-e #{OPTIONS[:environment]} " + - "-c #{OPTIONS[:rails_root]} " + - "-l #{OPTIONS[:rails_root]}/log/mongrel.log" - - # Add prefix functionality to spawner's call to mongrel_rails - # Digging through mongrel's project subversion server, the earliest - # Tag that has prefix implemented in the bin/mongrel_rails file - # is 0.3.15 which also happens to be the earliest tag listed. - # References: http://mongrel.rubyforge.org/svn/tags - if Mongrel::Const::MONGREL_VERSION.to_f >=0.3 && !OPTIONS[:prefix].nil? - cmd = cmd + " --prefix #{OPTIONS[:prefix]}" - end - system(cmd) - end - - def self.can_bind_to_custom_address? - true - end -end - - -begin - require_library_or_gem 'fcgi' -rescue Exception - # FCGI not available -end - -begin - require_library_or_gem 'mongrel' -rescue Exception - # Mongrel not available -end - -server = case ARGV.first - when "fcgi", "mongrel" - ARGV.shift - else - if defined?(Mongrel) - "mongrel" - elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `spawn-fcgi -version` }.blank? && defined?(FCGI) - "fcgi" - end -end - -case server - when "fcgi" - puts "=> Starting FCGI dispatchers" - spawner_class = FcgiSpawner - when "mongrel" - puts "=> Starting mongrel dispatchers" - spawner_class = MongrelSpawner - else - puts "Neither FCGI (spawn-fcgi) nor Mongrel was installed and available!" - exit(0) -end - - - -OPTIONS = { - :environment => "production", - :spawner => '/usr/bin/env spawn-fcgi', - :dispatcher => File.expand_path(RELATIVE_RAILS_ROOT + '/public/dispatch.fcgi'), - :pids => File.expand_path(RELATIVE_RAILS_ROOT + "/tmp/pids"), - :rails_root => File.expand_path(RELATIVE_RAILS_ROOT), - :process => "dispatch", - :port => 8000, - :address => '0.0.0.0', - :instances => 3, - :repeat => nil, - :prefix => nil -} - -ARGV.options do |opts| - opts.banner = "Usage: spawner [platform] [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The spawner is a wrapper for spawn-fcgi and mongrel that makes it - easier to start multiple processes running the Rails dispatcher. The - spawn-fcgi command is included with the lighttpd web server, but can - be used with both Apache and lighttpd (and any other web server - supporting externally managed FCGI processes). Mongrel automatically - ships with with mongrel_rails for starting dispatchers. - - The first choice you need to make is whether to spawn the Rails - dispatchers as FCGI or Mongrel. By default, this spawner will prefer - Mongrel, so if that's installed, and no platform choice is made, - Mongrel is used. - - Then decide a starting port (default is 8000) and the number of FCGI - process instances you'd like to run. So if you pick 9100 and 3 - instances, you'll start processes on 9100, 9101, and 9102. - - By setting the repeat option, you get a protection loop, which will - attempt to restart any FCGI processes that might have been exited or - outright crashed. - - You can select bind address for started processes. By default these - listen on every interface. For single machine installations you would - probably want to use 127.0.0.1, hiding them form the outside world. - - Examples: - spawner # starts instances on 8000, 8001, and 8002 - # using Mongrel if available. - spawner fcgi # starts instances on 8000, 8001, and 8002 - # using FCGI. - spawner mongrel -i 5 # starts instances on 8000, 8001, 8002, - # 8003, and 8004 using Mongrel. - spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to - # 9109 using Mongrel if available. - spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to - # 9102 and attempts start them every 5 - # seconds. - spawner -a 127.0.0.1 # starts 3 instances binding to localhost - EOF - - opts.on(" Options:") - - opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v } - - if spawner_class.can_bind_to_custom_address? - opts.on("-a", "--address=ip", String, "Bind to IP address (default: #{OPTIONS[:address]})") { |v| OPTIONS[:address] = v } - end - - opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v } - opts.on("-i", "--instances=number", Integer, "Number of instances (default: #{OPTIONS[:instances]})") { |v| OPTIONS[:instances] = v } - opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n seconds (default: off)") { |v| OPTIONS[:repeat] = v } - opts.on("-e", "--environment=name", String, "test|development|production (default: #{OPTIONS[:environment]})") { |v| OPTIONS[:environment] = v } - opts.on("-P", "--prefix=path", String, "URL prefix for Rails app. [Used only with Mongrel > v0.3.15]: (default: #{OPTIONS[:prefix]})") { |v| OPTIONS[:prefix] = v } - opts.on("-n", "--process=name", String, "default: #{OPTIONS[:process]}") { |v| OPTIONS[:process] = v } - opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}") { |v| OPTIONS[:spawner] = v } - opts.on("-d", "--dispatcher=path", String, "default: #{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] = File.expand_path(dispatcher) } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -ENV["RAILS_ENV"] = OPTIONS[:environment] - -if OPTIONS[:repeat] - daemonize - trap("TERM") { exit } - spawner_class.record_pid - - loop do - spawner_class.spawn_all - sleep(OPTIONS[:repeat]) - end -else - spawner_class.spawn_all -end diff --git a/railties/lib/commands/process/spinner.rb b/railties/lib/commands/process/spinner.rb deleted file mode 100644 index c0b2f09a94..0000000000 --- a/railties/lib/commands/process/spinner.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'optparse' - -def daemonize #:nodoc: - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - Dir.chdir "/" # Release old working directory. - File.umask 0000 # Ensure sensible umask. Adjust as needed. - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. -end - -OPTIONS = { - :interval => 5.0, - :command => File.expand_path(RAILS_ROOT + '/script/process/spawner'), - :daemon => false -} - -ARGV.options do |opts| - opts.banner = "Usage: spinner [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The spinner is a protection loop for the spawner, which will attempt to restart any FCGI processes - that might have been exited or outright crashed. It's a brute-force attempt that'll just try - to run the spawner every X number of seconds, so it does pose a light load on the server. - - Examples: - spinner # attempts to run the spawner with default settings every second with output on the terminal - spinner -i 3 -d # only run the spawner every 3 seconds and detach from the terminal to become a daemon - spinner -c '/path/to/app/script/process/spawner -p 9000 -i 10' -d # using custom spawner - EOF - - opts.on(" Options:") - - opts.on("-c", "--command=path", String) { |v| OPTIONS[:command] = v } - opts.on("-i", "--interval=seconds", Float) { |v| OPTIONS[:interval] = v } - opts.on("-d", "--daemon") { |v| OPTIONS[:daemon] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -daemonize if OPTIONS[:daemon] - -trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit } - -loop do - system(OPTIONS[:command]) - sleep(OPTIONS[:interval]) -end \ No newline at end of file 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 5435b2aeb3..fb3a407d2e 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -85,7 +85,6 @@ class AppGenerator < Rails::Generator::Base public/javascripts public/stylesheets script/performance - script/process test/fixtures test/functional test/integration @@ -139,8 +138,8 @@ class AppGenerator < Rails::Generator::Base def create_script_files(m) %w( - about console dbconsole destroy generate performance/benchmarker performance/profiler - performance/request process/reaper process/spawner process/inspector runner server plugin + about console dbconsole destroy generate runner server plugin + performance/benchmarker performance/profiler performance/request ).each do |file| m.file "bin/#{file}", "script/#{file}", { :chmod => 0755, -- cgit v1.2.3 From 926844e869b747fa1e9474fd95f9b97fa04ae092 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 28 Nov 2008 17:36:17 -0600 Subject: Switch FCGI handler over to Rack --- railties/lib/fcgi_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index 1bb55b9275..1256ef2286 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -98,7 +98,7 @@ class RailsFCGIHandler with_signal_handler 'USR1' do begin - Dispatcher.dispatch(cgi) + ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new) rescue SignalException, SystemExit raise rescue Exception => error -- cgit v1.2.3 From 61958032d3dbb8da8363d02ccda8933b99421fb1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 1 Dec 2008 12:21:18 -0600 Subject: Generate rackup dispatcher with rails:update:generate_dispatchers --- railties/lib/commands/server.rb | 20 +++++++++++--------- .../generators/applications/app/app_generator.rb | 1 + railties/lib/tasks/framework.rake | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index a4bb52592f..3611f80ed3 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -65,7 +65,6 @@ end ENV["RAILS_ENV"] = options[:environment] RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) -require RAILS_ROOT + "/config/environment" if File.exist?(options[:config]) config = options[:config] @@ -74,20 +73,23 @@ if File.exist?(options[:config]) if cfgfile[/^#\\(.*)/] opts.parse!($1.split(/\s+/)) end - app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) + inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) else require config - app = Object.const_get(File.basename(config, '.rb').capitalize) + inner_app = Object.const_get(File.basename(config, '.rb').capitalize) end else - app = Rack::Builder.new { - use Rails::Rack::Logger - use Rails::Rack::Static - use Rails::Rack::Debugger if options[:debugger] - run ActionController::Dispatcher.new - }.to_app + require RAILS_ROOT + "/config/environment" end +inner_app = ActionController::Dispatcher.new +app = Rack::Builder.new { + use Rails::Rack::Logger + use Rails::Rack::Static + use Rails::Rack::Debugger if options[:debugger] + run inner_app +}.to_app + puts "=> Call with -d to detach" trap(:INT) { exit } 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 fb3a407d2e..4bb94ff96d 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -197,6 +197,7 @@ class AppGenerator < Rails::Generator::Base if options[:with_dispatchers] dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } + m.file "dispatches/config.ru", "config.ru" m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index df080e94ac..d639214ffe 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -128,6 +128,7 @@ namespace :rails do desc "Generate dispatcher files in RAILS_ROOT/public" task :generate_dispatchers do require 'railties_path' + FileUtils.cp(RAILTIES_PATH + '/dispatches/config.ru', RAILS_ROOT + '/config.ru') FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.fcgi', RAILS_ROOT + '/public/dispatch.fcgi') FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.rb') FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.cgi') -- cgit v1.2.3 From 25f6524b89900378d08de9ec45757813dbb650cf Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 1 Dec 2008 12:24:02 -0600 Subject: opps, inner_app is in the wrong conditional --- railties/lib/commands/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 3611f80ed3..7057fcc33f 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -80,9 +80,9 @@ if File.exist?(options[:config]) end else require RAILS_ROOT + "/config/environment" + inner_app = ActionController::Dispatcher.new end -inner_app = ActionController::Dispatcher.new app = Rack::Builder.new { use Rails::Rack::Logger use Rails::Rack::Static -- cgit v1.2.3 From 3c07a8828ede3d41000513af29c293ae2e2a49d4 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 24 Nov 2008 23:07:12 -0500 Subject: handle missing dependecies in gem loading Signed-off-by: Michael Koziarski --- railties/lib/rails/gem_dependency.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index cd280ac023..5a07841be8 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -74,6 +74,7 @@ module Rails def dependencies return [] if framework_gem? + return [] if specification.nil? all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end -- cgit v1.2.3 From 06ed8e451198b2296d8b2752741e259b4f995081 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 1 Dec 2008 13:48:47 -0600 Subject: Add internal middleware stack to Dispatcher config.middleware.use Rack::Cache --- railties/lib/initializer.rb | 5 +++++ railties/lib/tasks/middleware.rake | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 railties/lib/tasks/middleware.rake (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a134c68a50..4bb1e480b7 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -881,6 +881,11 @@ Run `rake gems:install` to install the missing gems. end end + def middleware + require 'action_controller' + ActionController::Dispatcher.middleware + end + def builtin_directories # Include builtins only in the development environment. (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] diff --git a/railties/lib/tasks/middleware.rake b/railties/lib/tasks/middleware.rake new file mode 100644 index 0000000000..e0dcf50307 --- /dev/null +++ b/railties/lib/tasks/middleware.rake @@ -0,0 +1,7 @@ +desc 'Prints out your Rack middleware stack' +task :middleware => :environment do + ActionController::Dispatcher.middleware.each do |middleware| + puts "use #{middleware.inspect}" + end + puts "run ActionController::Dispatcher.new" +end -- cgit v1.2.3 From a8fc494dbb86be13248613565c0b611c561cdc48 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 1 Dec 2008 21:19:55 +0100 Subject: Manually load the DB config rather than firing the whole initializer [Gerrit Kaiser] --- railties/lib/tasks/databases.rake | 13 +++++++++---- railties/lib/tasks/misc.rake | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 5cb27f1f10..2140adb76e 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -1,7 +1,12 @@ namespace :db do + task :load_config => :rails_env do + require 'active_record' + ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration + end + namespace :create do desc 'Create all the local databases defined in config/database.yml' - task :all => :environment do + task :all => :load_config do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key, such as the first entry here: # @@ -22,7 +27,7 @@ namespace :db do end desc 'Create the database defined in config/database.yml for the current RAILS_ENV' - task :create => :environment do + task :create => :load_config do create_database(ActiveRecord::Base.configurations[RAILS_ENV]) end @@ -76,7 +81,7 @@ namespace :db do namespace :drop do desc 'Drops all the local databases defined in config/database.yml' - task :all => :environment do + task :all => :load_config do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key next unless config['database'] @@ -87,7 +92,7 @@ namespace :db do end desc 'Drops the database for the current RAILS_ENV' - task :drop => :environment do + task :drop => :load_config do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] begin drop_database(config) diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake index 5c99725203..411750bf40 100644 --- a/railties/lib/tasks/misc.rake +++ b/railties/lib/tasks/misc.rake @@ -3,6 +3,12 @@ task :environment do require(File.join(RAILS_ROOT, 'config', 'environment')) end +task :rails_env do + unless defined? RAILS_ENV + RAILS_ENV = ENV['RAILS_ENV'] ||= 'development' + end +end + desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.' task :secret do puts ActiveSupport::SecureRandom.hex(64) -- cgit v1.2.3 From a0bc480e1ddcaa015927c2d941e7b96a8ce4f6fa Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Fri, 28 Nov 2008 17:09:46 +0200 Subject: establish mysql connection before dropping database Signed-off-by: Michael Koziarski [#63 state:committed] --- railties/lib/tasks/databases.rake | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 2140adb76e..a90c1d4a77 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -398,6 +398,7 @@ end def drop_database(config) case config['adapter'] when 'mysql' + ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database config['database'] when /^sqlite/ FileUtils.rm(File.join(RAILS_ROOT, config['database'])) -- cgit v1.2.3 From e8cc4b116c460c524961a07da92da3f323854c15 Mon Sep 17 00:00:00 2001 From: Jeremy McAnally Date: Tue, 2 Dec 2008 17:22:27 +0100 Subject: Add "-m/--template" option to Rails generator to apply template to generated application. Signed-off-by: Pratik Naik --- railties/lib/rails_generator/base.rb | 3 + railties/lib/rails_generator/commands.rb | 1 + .../generators/applications/app/app_generator.rb | 12 + .../generators/applications/app/scm/git.rb | 16 + .../generators/applications/app/scm/scm.rb | 8 + .../generators/applications/app/scm/svn.rb | 7 + .../generators/applications/app/template_runner.rb | 376 +++++++++++++++++++++ 7 files changed, 423 insertions(+) create mode 100644 railties/lib/rails_generator/generators/applications/app/scm/git.rb create mode 100644 railties/lib/rails_generator/generators/applications/app/scm/scm.rb create mode 100644 railties/lib/rails_generator/generators/applications/app/scm/svn.rb create mode 100644 railties/lib/rails_generator/generators/applications/app/template_runner.rb (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb index b5cfe79867..aa7081f8da 100644 --- a/railties/lib/rails_generator/base.rb +++ b/railties/lib/rails_generator/base.rb @@ -154,6 +154,9 @@ module Rails File.join(destination_root, relative_destination) end + def after_generate + end + protected # Convenience method for generator subclasses to record a manifest. def record diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 6b9a636847..cacb3807d6 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -40,6 +40,7 @@ module Rails # Replay action manifest. RewindBase subclass rewinds manifest. def invoke! manifest.replay(self) + after_generate end def dependency(generator_name, args, runtime_options = {}) 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 4bb94ff96d..4a191578cf 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -1,4 +1,5 @@ require 'rbconfig' +require File.dirname(__FILE__) + '/template_runner' require 'digest/md5' require 'active_support/secure_random' @@ -37,6 +38,12 @@ class AppGenerator < Rails::Generator::Base end end + def after_generate + if options[:template] + Rails::TemplateRunner.new(@destination_root, options[:template]) + end + end + protected def banner "Usage: #{$0} /path/to/your/app [options]" @@ -60,6 +67,11 @@ class AppGenerator < Rails::Generator::Base opt.on("-f", "--freeze", "Freeze Rails in vendor/rails from the gems generating the skeleton", "Default: false") { |v| options[:freeze] = v } + + opt.on("-m", "--template=path", String, + "Use an application template that lives at path (can be a filesystem path or URL).", + "Default: (none)") { |v| options[:template] = v } + end diff --git a/railties/lib/rails_generator/generators/applications/app/scm/git.rb b/railties/lib/rails_generator/generators/applications/app/scm/git.rb new file mode 100644 index 0000000000..445de6ab42 --- /dev/null +++ b/railties/lib/rails_generator/generators/applications/app/scm/git.rb @@ -0,0 +1,16 @@ +module Rails + class Git < Scm + def self.clone(repos, branch=nil) + `git clone #{repos}` + + if branch + `cd #{repos.split('/').last}/` + `git checkout #{branch}` + end + end + + def self.run(command) + `git #{command}` + end + end +end \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/scm/scm.rb b/railties/lib/rails_generator/generators/applications/app/scm/scm.rb new file mode 100644 index 0000000000..f6c08cad39 --- /dev/null +++ b/railties/lib/rails_generator/generators/applications/app/scm/scm.rb @@ -0,0 +1,8 @@ +module Rails + class Scm + private + def self.hash_to_parameters(hash) + hash.collect { |key, value| "--#{key} #{(value.kind_of?(String) ? value : "")}"}.join(" ") + end + end +end \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/scm/svn.rb b/railties/lib/rails_generator/generators/applications/app/scm/svn.rb new file mode 100644 index 0000000000..22b5966d25 --- /dev/null +++ b/railties/lib/rails_generator/generators/applications/app/scm/svn.rb @@ -0,0 +1,7 @@ +module Rails + class Svn < Scm + def self.checkout(repos, branch = nil) + `svn checkout #{repos}/#{branch || "trunk"}` + end + end +end \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb new file mode 100644 index 0000000000..6f988df4bf --- /dev/null +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -0,0 +1,376 @@ +require File.dirname(__FILE__) + '/scm/scm' +require File.dirname(__FILE__) + '/scm/git' +require File.dirname(__FILE__) + '/scm/svn' + +require 'open-uri' +require 'fileutils' + +module Rails + class TemplateRunner + attr_reader :behavior, :description, :root + + def initialize(root, template) # :nodoc: + @root = Dir.pwd + "/" + root + + puts "applying template: #{template}" + + load_template(template) + + puts "#{template} applied." + end + + def load_template(template) + begin + code = open(template).read + in_root { self.instance_eval(code) } + rescue LoadError + raise "The template [#{template}] could not be loaded." + end + end + + # Create a new file in the Rails project folder. Specify the + # relative path from RAILS_ROOT. Data is the return value of a block + # or a data string. + # + # ==== Examples + # + # file("lib/fun_party.rb") do + # hostname = ask("What is the virtual hostname I should use?") + # "vhost.name = #{hostname}" + # end + # + # file("config/apach.conf", "your apache config") + # + def file(filename, data = nil, &block) + puts "creating file #{filename}" + dir, file = [File.dirname(filename), File.basename(filename)] + + inside(dir) do + File.open(file, "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Install a plugin. You must provide either a Subversion url or Git url. + # + # ==== Examples + # + # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git' + # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk' + # + def plugin(name, options) + puts "installing plugin #{name}" + + if options[:git] || options[:svn] + in_root do + `script/plugin install #{options[:svn] || options[:git]}` + end + else + puts "! no git or svn provided for #{name}. skipping..." + end + end + + # Adds an entry into config/environment.rb for the supplied gem : + # + # 1. Provide a git repository URL... + # + # gem 'will-paginate', :git => 'git://github.com/mislav/will_paginate.git' + # + # 2. Provide a subversion repository URL... + # + # gem 'will-paginate', :svn => 'svn://svnhub.com/mislav/will_paginate/trunk' + # + # 3. Provide a gem name and use your system sources to install and unpack it. + # + # gem 'ruby-openid' + # + def gem(name, options = {}) + puts "adding gem #{name}" + + sentinel = 'Rails::Initializer.run do |config|' + gems_code = "config.gem '#{name}'" + + if options.any? + opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.join(", ") + gems_code << ", #{opts}" + end + + in_root do + gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n #{gems_code}" + end + end + end + + # Run a command in git. + # + # ==== Examples + # + # git :init + # git :add => "this.file that.rb" + # git :add => "onefile.rb", :rm => "badfile.cxx" + # + def git(command = {}) + puts "running git #{command}" + + in_root do + if command.is_a?(Symbol) + Git.run(command.to_s) + else + command.each do |command, options| + Git.run("#{command} #{options}") + end + end + end + end + + # Create a new file in the vendor/ directory. Code can be specified + # in a block or a data string can be given. + # + # ==== Examples + # + # vendor("sekrit.rb") do + # sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--" + # "salt = '#{sekrit_salt}'" + # end + # + # vendor("foreign.rb", "# Foreign code is fun") + # + def vendor(filename, data = nil, &block) + puts "vendoring file #{filename}" + inside("vendor") do |folder| + File.open("#{folder}/#{filename}", "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Create a new file in the lib/ directory. Code can be specified + # in a block or a data string can be given. + # + # ==== Examples + # + # lib("crypto.rb") do + # "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'" + # end + # + # lib("foreign.rb", "# Foreign code is fun") + # + def lib(filename, data = nil) + puts "add lib file #{filename}" + inside("lib") do |folder| + File.open("#{folder}/#{filename}", "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Create a new Rakefile with the provided code (either in a block or a string). + # + # ==== Examples + # + # rakefile("bootstrap.rake") do + # project = ask("What is the UNIX name of your project?") + # + # <<-TASK + # namespace :#{project} do + # task :bootstrap do + # puts "i like boots!" + # end + # end + # TASK + # end + # + # rakefile("seed.rake", "puts 'im plantin ur seedz'") + # + def rakefile(filename, data = nil, &block) + puts "adding rakefile #{filename}" + inside("lib/tasks") do |folder| + File.open("#{folder}/#{filename}", "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Create a new initializer with the provided code (either in a block or a string). + # + # ==== Examples + # + # initializer("globals.rb") do + # data = "" + # + # ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do + # data << "#{const} = :entp" + # end + # + # data + # end + # + # initializer("api.rb", "API_KEY = '123456'") + # + def initializer(filename, data = nil, &block) + puts "adding initializer #{filename}" + inside("config/initializers") do |folder| + File.open("#{folder}/#{filename}", "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Generate something using a generator from Rails or a plugin. + # The second parameter is the argument string that is passed to + # the generator or an Array that is joined. + # + # ==== Example + # + # generate(:authenticated, "user session") + # + def generate(what, args = nil) + puts "generating #{what}" + args = args.join(" ") if args.class == Array + + in_root { `#{root}/script/generate #{what} #{args}` } + end + + # Executes a command + # + # ==== Example + # + # inside('vendor') do + # run('ln -s ~/edge rails) + # end + # + def run(command) + puts "executing #{command} from #{Dir.pwd}" + `#{command}` + end + + # Runs the supplied rake task + # + # ==== Example + # + # rake("db:migrate") + # rake("db:migrate", "production") + # + def rake(command, env = 'development') + puts "running rake task #{command}" + in_root { `rake #{command} RAILS_ENV=#{env}` } + end + + # Just run the capify command in root + # + # ==== Example + # + # capify! + # + def capify! + in_root { `capify .` } + end + + # Add Rails to /vendor/rails + # + # ==== Example + # + # freeze! + # + def freeze!(args = {}) + puts "vendoring rails edge" + in_root { `rake rails:freeze:edge` } + end + + # Make an entry in Rails routing file conifg/routes.rb + # + # === Example + # + # route "map.root :controller => :welcome" + # + def route(routing_code) + sentinel = 'ActionController::Routing::Routes.draw do |map|' + + in_root do + gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n #{routing_code}\n" + end + end + end + + protected + + # Get a user's input + # + # ==== Example + # + # answer = ask("Should I freeze the latest Rails?") + # freeze! if ask("Should I freeze the latest Rails?") == "yes" + # + def ask(string) + puts string + gets.strip + end + + # Do something in the root of the Rails application or + # a provided subfolder; the full path is yielded to the block you provide. + # The path is set back to the previous path when the method exits. + def inside(dir = '', &block) + folder = File.join(root, dir) + FileUtils.mkdir_p(folder) unless File.exist?(folder) + FileUtils.cd(folder) { block.arity == 1 ? yield(folder) : yield } + end + + def in_root + FileUtils.cd(root) { yield } + end + + # Helper to test if the user says yes(y)? + # + # ==== Example + # + # freeze! if yes?("Should I freeze the latest Rails?") + # + def yes?(question) + answer = ask(question).downcase + answer == "y" || answer == "yes" + end + + # Helper to test if the user does NOT say yes(y)? + # + # ==== Example + # + # capify! if no?("Will you be using vlad to deploy your application?") + # + def no?(question) + !yes?(question) + end + + def gsub_file(relative_destination, regexp, *args, &block) + path = destination_path(relative_destination) + content = File.read(path).gsub(regexp, *args, &block) + File.open(path, 'wb') { |file| file.write(content) } + end + + def destination_path(relative_destination) + File.join(root, relative_destination) + end + end +end \ No newline at end of file -- cgit v1.2.3 From be75cb8877e84e8d312402435eeb02d7ea6af600 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 2 Dec 2008 19:48:25 +0100 Subject: Remove docs for TemplateRunner#gem as the behaviour has been changed --- .../generators/applications/app/template_runner.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index 6f988df4bf..0083e0d5a5 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -76,19 +76,6 @@ module Rails end # Adds an entry into config/environment.rb for the supplied gem : - # - # 1. Provide a git repository URL... - # - # gem 'will-paginate', :git => 'git://github.com/mislav/will_paginate.git' - # - # 2. Provide a subversion repository URL... - # - # gem 'will-paginate', :svn => 'svn://svnhub.com/mislav/will_paginate/trunk' - # - # 3. Provide a gem name and use your system sources to install and unpack it. - # - # gem 'ruby-openid' - # def gem(name, options = {}) puts "adding gem #{name}" -- cgit v1.2.3 From 0b4858cf38f522208381f9bfbbb5c066aceb30d2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 3 Dec 2008 10:23:58 -0600 Subject: Require rack/utils explicitly --- railties/lib/rails/rack/static.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb index 45eb0e5921..ef4e2642e2 100644 --- a/railties/lib/rails/rack/static.rb +++ b/railties/lib/rails/rack/static.rb @@ -1,3 +1,5 @@ +require 'rack/utils' + module Rails module Rack class Static -- cgit v1.2.3