From 44f02de2ad6d22d0d781c0c7303bcd8162aaa5d6 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Sun, 1 Feb 2009 10:41:57 -0600 Subject: Update scaffolding [#1840 state:committed] Signed-off-by: David Heinemeier Hansson --- .../generators/components/scaffold/templates/controller.rb | 2 +- .../generators/components/scaffold/templates/view_index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb index cbfd88f3bd..4d190b9362 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb @@ -2,7 +2,7 @@ class <%= controller_class_name %>Controller < ApplicationController # GET /<%= table_name %> # GET /<%= table_name %>.xml def index - @<%= table_name %> = <%= class_name %>.find(:all) + @<%= table_name %> = <%= class_name %>.all respond_to do |format| format.html # index.html.erb diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb index e89757e3e9..f51fe85dc9 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb @@ -7,7 +7,7 @@ <% end -%> -<%% for <%= singular_name %> in @<%= plural_name %> %> +<%% @<%= plural_name %>.each do |<%= singular_name %>| %> <% for attribute in attributes -%> <%%=h <%= singular_name %>.<%= attribute.name %> %> -- cgit v1.2.3 From a2da7fd349b3e8fbeb814a64c9bb6b7c91290257 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 5 Feb 2009 20:30:33 +0100 Subject: A few more minor scaffold template cleanups --- .../generators/components/scaffold/templates/layout.html.erb | 2 +- .../generators/components/scaffold/templates/view_edit.html.erb | 4 ++-- .../generators/components/scaffold/templates/view_index.html.erb | 2 +- .../generators/components/scaffold/templates/view_new.html.erb | 4 ++-- .../generators/components/scaffold/templates/view_show.html.erb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb index 5c1f304232..ebc97f8130 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb @@ -11,7 +11,7 @@

<%%= flash[:notice] %>

-<%%= yield %> +<%%= yield %> diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb index e289975596..cca1d61c68 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb @@ -10,9 +10,9 @@

<% end -%>

- <%%= f.submit "Update" %> + <%%= f.submit 'Update' %>

<%% end %> <%%= link_to 'Show', @<%= singular_name %> %> | -<%%= link_to 'Back', <%= plural_name %>_path %> +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb index f51fe85dc9..2e603d5b4a 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb @@ -21,4 +21,4 @@
-<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %> +<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %> \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb index c47e8117b4..96c89fc50e 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb @@ -10,8 +10,8 @@

<% end -%>

- <%%= f.submit "Create" %> + <%%= f.submit 'Create' %>

<%% end %> -<%%= link_to 'Back', <%= plural_name %>_path %> +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb index 9b6b11b029..adecaf70c6 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb @@ -7,4 +7,4 @@ <% end -%> <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> | -<%%= link_to 'Back', <%= plural_name %>_path %> +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file -- cgit v1.2.3 From b6e7a76cc573ee35c1df648f35d5865672f55e15 Mon Sep 17 00:00:00 2001 From: Chris Cherry Date: Thu, 5 Feb 2009 15:19:40 -0600 Subject: script/server command can accept --path option to set app's root path [#1156 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/commands/server.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index 43b18004c0..ebe34a42cd 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -17,7 +17,8 @@ options = { :environment => (ENV['RAILS_ENV'] || "development").dup, :config => RAILS_ROOT + "/config.ru", :detach => false, - :debugger => false + :debugger => false, + :path => nil } ARGV.clone.options do |opts| @@ -32,6 +33,7 @@ ARGV.clone.options do |opts| 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("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: /") { |v| options[:path] = v } opts.separator "" @@ -50,7 +52,7 @@ unless server end puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" -puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}" +puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}" %w(cache pids sessions sockets).each do |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) @@ -83,11 +85,20 @@ else inner_app = ActionController::Dispatcher.new end +if options[:path].nil? + map_path = "/" +else + ActionController::Base.relative_url_root = options[:path] + map_path = options[:path] +end + app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] - use Rails::Rack::Static use Rails::Rack::Debugger if options[:debugger] - run inner_app + map map_path do + use Rails::Rack::Static + run inner_app + end }.to_app puts "=> Call with -d to detach" -- cgit v1.2.3 From dcc2407d9976740cebe6736ec6adeae269b81203 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 5 Feb 2009 16:21:50 -0600 Subject: Fixed FCGI handling [#1854 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/fcgi_handler.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index 1256ef2286..53f555d5e1 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -1,3 +1,4 @@ +FCGI_PURE_RUBY = true require 'fcgi' require 'logger' require 'dispatcher' @@ -98,6 +99,7 @@ class RailsFCGIHandler with_signal_handler 'USR1' do begin + cgi = FCGI::Request.new(cgi.id, cgi.env_table, cgi.stdinput, cgi.stdoutput) ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new) rescue SignalException, SystemExit raise -- cgit v1.2.3 From c96382a71a77505ea2f51e43bc81fdb3ac95d117 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 5 Feb 2009 16:39:32 -0600 Subject: Make sure all autoload constants are pulled in when using config.threadsafe! [#1831 state:resolved] --- 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 da064c86aa..e3811dd8be 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -132,10 +132,10 @@ module Rails add_gem_load_paths require_frameworks - preload_frameworks set_autoload_paths add_plugin_load_paths load_environment + preload_frameworks initialize_encoding initialize_database @@ -270,7 +270,7 @@ module Rails 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! + toplevel.load_all! if toplevel.respond_to?(:load_all!) end end end -- cgit v1.2.3 From ba146a84d0ed8a886fdc6b6794ce99a9d37c0190 Mon Sep 17 00:00:00 2001 From: Will Bryant Date: Wed, 19 Nov 2008 22:44:54 +1300 Subject: re-enable db:schema:dump so db:migrate:redo dumps the schema after migrating back up Signed-off-by: Michael Koziarski [#1412 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 68ffefae0b..9588fabb2d 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -250,6 +250,7 @@ namespace :db do File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end + Rake::Task["db:schema:dump"].reenable end desc "Load a schema.rb file into the database" -- cgit v1.2.3 From f75b98d67ed9ef85d20858a1d24ee6767d64ece6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 5 Feb 2009 19:39:53 -0600 Subject: Revert "Fixed FCGI handling [#1854 state:resolved]" This reverts commit dcc2407d9976740cebe6736ec6adeae269b81203. --- railties/lib/fcgi_handler.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index 53f555d5e1..1256ef2286 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -1,4 +1,3 @@ -FCGI_PURE_RUBY = true require 'fcgi' require 'logger' require 'dispatcher' @@ -99,7 +98,6 @@ class RailsFCGIHandler with_signal_handler 'USR1' do begin - cgi = FCGI::Request.new(cgi.id, cgi.env_table, cgi.stdinput, cgi.stdoutput) ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new) rescue SignalException, SystemExit raise -- cgit v1.2.3 From 96d610553e5fdaabc923835ab1f194070ddb4477 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 6 Feb 2009 01:57:02 +0000 Subject: Merge docrails along with the new guides and guides generation code --- railties/lib/tasks/documentation.rake | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/tasks/documentation.rake b/railties/lib/tasks/documentation.rake index 6caf69ccd3..8b41478a93 100644 --- a/railties/lib/tasks/documentation.rake +++ b/railties/lib/tasks/documentation.rake @@ -54,15 +54,8 @@ namespace :doc do desc "Generate Rails guides" task :guides do - source = File.join(RAILTIES_PATH, "doc/guides") - destination = File.join(RAILS_ROOT, "doc/guides") - FileUtils.rm_r(destination) if File.directory?(destination) - FileUtils.mkdir(destination) - - FileUtils.cp_r File.join(source, 'html/.'), File.join(destination) - # Copy images and css files to html directory. These dirs are in .gitigore and shouldn't be source controlled. - FileUtils.cp_r File.join(source, 'source/images'), File.join(destination) - FileUtils.cp_r File.join(source, 'source/stylesheets'), File.join(destination, 'stylesheets') + require File.join(RAILTIES_PATH, "guides/rails_guides") + RailsGuides::Generator.new(File.join(RAILS_ROOT, "doc/guides")).generate end namespace :plugins do -- cgit v1.2.3 From be098f840614bbb71fe26f0e2b4c064b6866c076 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 5 Feb 2009 20:39:52 -0600 Subject: Cleanup application has been merged with reload --- railties/lib/console_app.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index 96bf3117c8..a35c96c957 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -25,7 +25,6 @@ end def reload! puts "Reloading..." dispatcher = ActionController::Dispatcher.new($stdout) - dispatcher.cleanup_application dispatcher.reload_application true end -- cgit v1.2.3 From 2316e7dfb16518d4d0d92165bcd53b262080fc37 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 7 Feb 2009 00:25:07 -0600 Subject: Fix FCGI handler with lighttpd [#1854 state:resolved] --- railties/lib/fcgi_handler.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index 1256ef2286..9e508cbcc2 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -38,6 +38,8 @@ class RailsFCGIHandler # Safely install signal handlers. install_signal_handlers + @app = Dispatcher.new + # Start error timestamp at 11 seconds ago. @last_error_on = Time.now - 11 end @@ -72,8 +74,8 @@ class RailsFCGIHandler cgi = nil catch :exit do - provider.each_cgi do |cgi| - process_request(cgi) + provider.each do |request| + process_request(request) case when_ready when :reload @@ -92,13 +94,13 @@ class RailsFCGIHandler close_connection(cgi) end - def process_request(cgi) + def process_request(request) @processing, @when_ready = true, nil gc_countdown with_signal_handler 'USR1' do begin - ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new) + ::Rack::Handler::FastCGI.serve(request, @app) rescue SignalException, SystemExit raise rescue Exception => error -- cgit v1.2.3 From f98d8ee72b2fd92bf0e09f3cade60add9efd3a15 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 7 Feb 2009 00:35:15 -0600 Subject: Fix up failing tests broke by 2316e7d --- railties/lib/fcgi_handler.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index 9e508cbcc2..0cd2dc51c6 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -71,7 +71,7 @@ class RailsFCGIHandler protected def process_each_request(provider) - cgi = nil + request = nil catch :exit do provider.each do |request| @@ -81,17 +81,17 @@ class RailsFCGIHandler when :reload reload! when :restart - close_connection(cgi) + close_connection(request) restart! when :exit - close_connection(cgi) + close_connection(request) throw :exit end end end rescue SignalException => signal raise unless signal.message == 'SIGUSR1' - close_connection(cgi) + close_connection(request) end def process_request(request) @@ -233,7 +233,7 @@ class RailsFCGIHandler end end - def close_connection(cgi) - cgi.instance_variable_get("@request").finish if cgi + def close_connection(request) + request.finish if request end end -- cgit v1.2.3 From 893e9eb99504705419ad6edac14d00e71cef5f12 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 9 Feb 2009 14:20:30 -0600 Subject: Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index e3811dd8be..2cc0943b78 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -181,9 +181,6 @@ module Rails # Observers are loaded after plugins in case Observers or observed models are modified by plugins. load_observers - # Load view path cache - load_view_paths - # Load application classes load_application_classes @@ -367,16 +364,6 @@ Run `rake gems:install` to install the missing gems. end end - def load_view_paths - if configuration.frameworks.include?(:action_view) - if configuration.cache_classes - view_path = ActionView::Template::EagerPath.new(configuration.view_path) - ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) - end - end - end - # Eager load application classes def load_application_classes return if $rails_rake_task -- cgit v1.2.3 From 5c63be1f92edcd3ed60fae90b8eb129da19c5099 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Feb 2009 14:53:14 -0600 Subject: Still need to setup view paths --- railties/lib/initializer.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 2cc0943b78..11aa8a534e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -181,6 +181,9 @@ module Rails # Observers are loaded after plugins in case Observers or observed models are modified by plugins. load_observers + # Load view path cache + load_view_paths + # Load application classes load_application_classes @@ -364,6 +367,15 @@ Run `rake gems:install` to install the missing gems. end end + def load_view_paths + if configuration.frameworks.include?(:action_view) + if configuration.cache_classes + ActionController::Base.view_paths = configuration.view_path if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) + end + end + end + # Eager load application classes def load_application_classes return if $rails_rake_task -- cgit v1.2.3 From 1dab1d380377f1a2a60da43bc22989d55632d246 Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Tue, 10 Feb 2009 12:58:32 +0100 Subject: Fixes a typo in initializer.rb producing error: undefined local variable or method `view_path'. --- 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 11aa8a534e..39140065b0 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -371,7 +371,7 @@ Run `rake gems:install` to install the missing gems. if configuration.frameworks.include?(:action_view) if configuration.cache_classes ActionController::Base.view_paths = configuration.view_path if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) + ActionMailer::Base.template_root = configuration.view_path if configuration.frameworks.include?(:action_mailer) end end end -- cgit v1.2.3 From 199e750d46c04970b5e7684998d09405648ecbd4 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 10 Feb 2009 12:09:49 -0600 Subject: Fix some edge cases when the same template is called with different local assigns Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 39140065b0..c4c55a97eb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -369,10 +369,8 @@ 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 = configuration.view_path if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root = configuration.view_path if configuration.frameworks.include?(:action_mailer) - end + ActionController::Base.view_paths.each { |path| path.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 3942cb406e1d5db0ac00e03153809cc8dc4cc4db Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 12 Feb 2009 19:35:14 +0100 Subject: Port fast reloadable templates from rails-dev-boost. --- railties/lib/initializer.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index c4c55a97eb..281b074e0a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -369,8 +369,8 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - ActionController::Base.view_paths.each { |path| path.load! } if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load! if configuration.frameworks.include?(:action_mailer) + ActionController::Base.view_paths.load! if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.view_paths.load! if configuration.frameworks.include?(:action_mailer) end end @@ -478,7 +478,7 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views if configuration.frameworks.include?(:action_view) - view_path = ActionView::Template::Path.new(configuration.view_path) + view_path = ActionView::PathSet.type_cast(configuration.view_path) ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer) ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? end -- cgit v1.2.3 From 0c956443964a20cbcc122e2d8c429b0cbb121828 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Sun, 8 Feb 2009 11:36:01 -0500 Subject: Changed scaffold generated controller tests to use #to_param. Before, the generated controller tests were calling #id, which can change over time, making for brittle tests. Signed-off-by: Michael Koziarski [#1913 state:committed] --- .../generators/components/scaffold/templates/functional_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb index 2d9d635944..cd2fc578bf 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb @@ -21,23 +21,23 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase end test "should show <%= file_name %>" do - get :show, :id => <%= table_name %>(:one).id + get :show, :id => <%= table_name %>(:one).to_param assert_response :success end test "should get edit" do - get :edit, :id => <%= table_name %>(:one).id + get :edit, :id => <%= table_name %>(:one).to_param assert_response :success end test "should update <%= file_name %>" do - put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { } + put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { } assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) end test "should destroy <%= file_name %>" do assert_difference('<%= class_name %>.count', -1) do - delete :destroy, :id => <%= table_name %>(:one).id + delete :destroy, :id => <%= table_name %>(:one).to_param end assert_redirected_to <%= table_name %>_path -- cgit v1.2.3 From a6508527570cd3f7225a7030218447bcc5824224 Mon Sep 17 00:00:00 2001 From: Oshoma Momoh Date: Mon, 9 Feb 2009 10:29:15 -0500 Subject: Fix loader's LoadError exception message to mention missing plugins and omit loaded plugins. Prior to this change the LoadError message listed all plugins if any one of them was missing. Signed-off-by: Michael Koziarski [#1921 state:committed] --- railties/lib/rails/plugin/loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index be81bdf4fa..bc0184c43d 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -175,7 +175,7 @@ module Rails def ensure_all_registered_plugins_are_loaded! if explicit_plugin_loading_order? if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) } - missing_plugins = configuration.plugins - (plugins + [:all]) + missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all]) raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}" end end -- cgit v1.2.3 From 2414fdb244cc0ba97620dd3f50e269d2e26c7392 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Feb 2009 13:03:47 +0000 Subject: Ensure template_runner can run script/* ruby scripts under Windows. [#1859 state:resolved] Signed-off-by: Pratik Naik --- .../generators/applications/app/template_runner.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 84e36ecc1b..eeb6b17661 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -75,7 +75,7 @@ module Rails end elsif options[:git] || options[:svn] in_root do - run("script/plugin install #{options[:svn] || options[:git]}", false) + run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false) end else log "! no git or svn provided for #{name}. skipping..." @@ -220,7 +220,7 @@ module Rails log 'generating', what argument = args.map(&:to_s).flatten.join(" ") - in_root { run("script/generate #{what} #{argument}", false) } + in_root { run_ruby_script("script/generate #{what} #{argument}", false) } end # Executes a command @@ -236,6 +236,12 @@ module Rails `#{command}` end + # Executes a ruby script (taking into account WIN32 platform quirks) + def run_ruby_script(command, log_action = true) + ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : '' + run("#{ruby_command}#{command}", log_action) + end + # Runs the supplied rake task # # ==== Example -- cgit v1.2.3 From 69c049f5ab45bf9bfb0d269acea0773581905fd4 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 20 Feb 2009 12:04:57 -0600 Subject: Move development mode reloading up the stack to avoid issues with class reloading in middleware --- railties/lib/console_app.rb | 3 +-- railties/lib/initializer.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index a35c96c957..d7cd57564f 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -24,7 +24,6 @@ end #reloads the environment def reload! puts "Reloading..." - dispatcher = ActionController::Dispatcher.new($stdout) - dispatcher.reload_application + Dispatcher.reload_application true end diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 281b074e0a..7e1bd23a55 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -583,7 +583,7 @@ Run `rake gems:install` to install the missing gems. return unless configuration.frameworks.include?(:action_controller) require 'dispatcher' unless defined?(::Dispatcher) Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) - Dispatcher.new(Rails.logger).send :run_callbacks, :prepare_dispatch + Dispatcher.run_prepare_callbacks end def disable_dependency_loading -- cgit v1.2.3 From 01c818e99f04f70462df68e6a217dfd280c37581 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Fri, 20 Feb 2009 14:16:07 -0600 Subject: break out of initializer early if gems aren't loaded [#1750 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 6 +++++- railties/lib/tasks/gems.rake | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 7e1bd23a55..8221f1f2f2 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -167,6 +167,10 @@ module Rails load_gems check_gem_dependencies + # bail out if gems are missing - note that check_gem_dependencies will have + # already called abort() unless $gems_rake_task is set + return unless gems_dependencies_loaded + load_application_initializers # the framework is now fully initialized @@ -302,7 +306,7 @@ module Rails if unloaded_gems.size > 0 @gems_dependencies_loaded = false # don't print if the gems rake tasks are being run - unless $rails_rake_task + unless $gems_rake_task abort <<-end_error Missing these required gems: #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "} diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index e6731ab78c..d538e52ca6 100644 --- a/railties/lib/tasks/gems.rake +++ b/railties/lib/tasks/gems.rake @@ -17,13 +17,13 @@ end namespace :gems do task :base do - $rails_rake_task = true + $gems_rake_task = true Rake::Task[:environment].invoke end desc "Build any native extensions for unpacked gems" task :build do - $rails_rake_task = true + $gems_rake_task = true require 'rails/gem_builder' Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |gem_dir| spec_file = File.join(gem_dir, '.specification') -- cgit v1.2.3 From b61cad6ae140bc71c6a74b22c75e886b41154b0a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 22 Feb 2009 16:04:04 +0100 Subject: Ensure that the app routes file is loaded even when engines are in play (Thjis) [#1970 state:committed] --- 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 8221f1f2f2..eb8d3510c8 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -496,7 +496,7 @@ Run `rake gems:install` to install the missing gems. ActionController::Routing.controller_paths += configuration.controller_paths ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file) - ActionController::Routing::Routes.reload + ActionController::Routing::Routes.reload! end # Sets the dependency loading mechanism based on the value of -- cgit v1.2.3 From 441e4e22352c8805a882f6a661ab3982dd7eda12 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 22 Feb 2009 10:39:56 -0600 Subject: load plugin view_paths to action_mailer view_paths and make action_mailer use them [#2031 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 4 +-- railties/lib/rails/plugin/loader.rb | 50 +++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 26 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index eb8d3510c8..0e05634f4a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -483,8 +483,8 @@ Run `rake gems:install` to install the missing gems. def initialize_framework_views if configuration.frameworks.include?(:action_view) view_path = ActionView::PathSet.type_cast(configuration.view_path) - ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer) - ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? + ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) && ActionMailer::Base.view_paths.blank? + ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.blank? end end diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index bc0184c43d..7f85bb8966 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -16,7 +16,7 @@ module Rails def initialize(initializer) @initializer = initializer end - + # Returns the plugins to be loaded, in the order they should be loaded. def plugins @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) } @@ -32,9 +32,9 @@ module Rails @all_plugins ||= locate_plugins @all_plugins end - + def load_plugins - plugins.each do |plugin| + plugins.each do |plugin| plugin.load(initializer) register_plugin_as_loaded(plugin) end @@ -43,12 +43,12 @@ module Rails ensure_all_registered_plugins_are_loaded! end - + # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are # added *after* the application's lib directory, to ensure that an application # can always override code within a plugin. # - # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths. + # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths. def add_plugin_load_paths plugins.each do |plugin| plugin.load_paths.each do |path| @@ -56,7 +56,7 @@ module Rails ActiveSupport::Dependencies.load_paths << path - unless Rails.configuration.reload_plugins? + unless configuration.reload_plugins? ActiveSupport::Dependencies.load_once_paths << path end end @@ -64,8 +64,8 @@ module Rails $LOAD_PATH.uniq! end - - + + protected def configure_engines if engines.any? @@ -74,20 +74,22 @@ module Rails 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) + paths = ActionView::PathSet.new(engines.collect(&:view_path).reverse) + ActionController::Base.view_paths.concat(paths) + ActionMailer::Base.view_paths.concat(paths) if configuration.frameworks.include?(:action_mailer) end # The locate_plugins method uses each class in config.plugin_locators to @@ -106,7 +108,7 @@ module Rails def configuration initializer.configuration end - + def should_load?(plugin) # uses Plugin#name and Plugin#valid? enabled?(plugin) && plugin.valid? @@ -120,21 +122,21 @@ module Rails plugin_a <=> plugin_b else effective_order_of(plugin_a) <=> effective_order_of(plugin_b) - end + end end end - + def effective_order_of(plugin) if explicitly_enabled?(plugin) - registered_plugin_names.index(plugin.name) + registered_plugin_names.index(plugin.name) else registered_plugin_names.index('all') - end + end end def application_lib_index $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0 - end + end def enabled?(plugin) !explicit_plugin_loading_order? || registered?(plugin) @@ -155,23 +157,23 @@ module Rails def explicitly_registered?(plugin) explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name) end - + def registered_plugins_names_plugin?(plugin) registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all') end - + # The plugins that have been explicitly listed with config.plugins. If this list is nil - # then it means the client does not care which plugins or in what order they are loaded, + # then it means the client does not care which plugins or in what order they are loaded, # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is # non empty, we load the named plugins in the order specified. def registered_plugin_names configuration.plugins ? configuration.plugins.map(&:to_s) : nil end - + def loaded?(plugin_name) initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s } end - + def ensure_all_registered_plugins_are_loaded! if explicit_plugin_loading_order? if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) } @@ -180,7 +182,7 @@ module Rails end end end - + end end end \ No newline at end of file -- cgit v1.2.3 From 53cd102b39eb62567298430cbd94e40dd78d46a0 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 24 Feb 2009 12:29:25 +0000 Subject: Merge with docrails --- railties/lib/initializer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0e05634f4a..a31ae9422e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -838,7 +838,8 @@ Run `rake gems:install` to install the missing gems. # Enable threaded mode. Allows concurrent requests to controller actions and # multiple database connections. Also disables automatic dependency loading - # after boot + # after boot, and disables reloading code on every request, as these are + # fundamentally incompatible with thread safety. def threadsafe! self.preload_frameworks = true self.cache_classes = true -- cgit v1.2.3 From d32eb410f19f6872df1e1e1810840c0f5aa13b50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 24 Feb 2009 10:52:51 -0600 Subject: Put back dispatcher cleanup call in console reload! [#2056 state:resolved] --- railties/lib/console_app.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index d7cd57564f..d7d01d703f 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -24,6 +24,7 @@ end #reloads the environment def reload! puts "Reloading..." + Dispatcher.cleanup_application Dispatcher.reload_application true end -- cgit v1.2.3 From 1b22071b276a2a2b3e65e6db40c6a0aa92d9ebc3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 24 Feb 2009 11:34:32 -0600 Subject: Ensure ActiveRecord session store's connections are checked in after each request [#1927 state:resolved] --- railties/lib/initializer.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a31ae9422e..09affe9e36 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -176,6 +176,9 @@ module Rails # the framework is now fully initialized after_initialize + # Setup database middleware after initializers have run + initialize_database_middleware + # Prepare dispatcher callbacks and run 'prepare' callbacks prepare_dispatcher @@ -410,7 +413,18 @@ Run `rake gems:install` to install the missing gems. if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection - configuration.middleware.use ActiveRecord::QueryCache + end + end + + def initialize_database_middleware + if configuration.frameworks.include?(:active_record) + if ActionController::Base.session_store == ActiveRecord::SessionStore + configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement + configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache + else + configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement + configuration.middleware.use ActiveRecord::QueryCache + end end end -- cgit v1.2.3 From 6de83562f91028629bd24447aa521bc72ef8277a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 27 Feb 2009 14:22:39 +0100 Subject: Force all internal calls to Array#to_sentence to use English [#2010 state:resolved] --- railties/lib/rails/plugin/loader.rb | 2 +- railties/lib/tasks/testing.rake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 7f85bb8966..f86589a689 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -178,7 +178,7 @@ module Rails if explicit_plugin_loading_order? if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) } missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all]) - raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}" + raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence(:locale => :en)}" end end end diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake index 4242458672..fd5e52a05b 100644 --- a/railties/lib/tasks/testing.rake +++ b/railties/lib/tasks/testing.rake @@ -48,7 +48,7 @@ task :test do task end end.compact - abort "Errors running #{errors.to_sentence}!" if errors.any? + abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any? end namespace :test do -- cgit v1.2.3 From 319106d09c0ec2daf8b5345f525f1c97b6368ce2 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Sun, 22 Feb 2009 19:23:04 +0000 Subject: Metal can now line in plugins under app/metal [#2045 state:committed] Signed-off-by: David Heinemeier Hansson --- railties/lib/initializer.rb | 2 ++ railties/lib/rails/plugin.rb | 8 ++++++-- railties/lib/rails/plugin/loader.rb | 5 ++++- railties/lib/rails/rack/metal.rb | 15 +++++++++------ 4 files changed, 21 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 09affe9e36..24ce3e75ff 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -559,6 +559,8 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal + Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths + configuration.middleware.insert_before( :"ActionController::RewindableInput", Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 4901abe808..80deb73bbb 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -80,6 +80,10 @@ module Rails File.join(directory, 'app', 'controllers') end + def metal_path + File.join(directory, 'app', 'metal') + end + def routing_file File.join(directory, 'config', 'routes.rb') end @@ -100,7 +104,7 @@ module Rails def app_paths - [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ] + [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ] end def lib_path @@ -160,4 +164,4 @@ module Rails File.join(directory, 'rails', 'init.rb') end end -end \ No newline at end of file +end diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index f86589a689..66e01d70da 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -65,6 +65,9 @@ module Rails $LOAD_PATH.uniq! end + def engine_metal_paths + engines.collect(&:metal_path) + end protected def configure_engines @@ -185,4 +188,4 @@ module Rails end end -end \ No newline at end of file +end diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index b185227234..8dac992ef2 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -6,14 +6,17 @@ module Rails NotFoundResponse = [404, {}, []].freeze NotFound = lambda { NotFoundResponse } + cattr_accessor :metal_paths + self.metal_paths = ["#{Rails.root}/app/metal"] + def self.metals - base = "#{Rails.root}/app/metal" - matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/ + matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ + metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } - Dir["#{base}/**/*.rb"].sort.map do |file| - file.sub!(matcher, '\1') - require file - file.classify.constantize + Dir[*metal_glob].sort.map do |file| + path = file.match(matcher)[1] + require path + path.classify.constantize end end -- cgit v1.2.3 From 77b0994c7835610982d708ce7ce5cd95e6e99e5a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 27 Feb 2009 14:46:23 +0100 Subject: Prep for RC2 later today --- 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 9bb4b2a96d..fd38705e75 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 = 3 - TINY = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From eb217b2cf02af3d6533fb5b0e3fe87efa78cf43a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 27 Feb 2009 12:18:18 -0800 Subject: Ruby 1.9 compat: limit const_defined? --- railties/lib/rails_generator/commands.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 299044c3d7..b684dc92be 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -182,15 +182,19 @@ HELP nesting = class_name.split('::') name = nesting.pop + # Hack to limit const_defined? to non-inherited on 1.9. + extra = [] + extra << false unless Object.method(:const_defined?).arity == 1 + # Extract the last Module in the nesting. last = nesting.inject(Object) { |last, nest| - break unless last.const_defined?(nest) + break unless last.const_defined?(nest, *extra) last.const_get(nest) } # If the last Module exists, check whether the given # class exists and raise a collision if so. - if last and last.const_defined?(name.camelize) + if last and last.const_defined?(name.camelize, *extra) raise_class_collision(class_name) end end -- cgit v1.2.3 From 16b3d2b621b1682f249209097c31b0a10f0f87ef Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Sun, 15 Feb 2009 19:33:12 -0800 Subject: Added :env option for gem in template runner [#1983 state:resolved] For installing gems that are only needed in the test environment, specify the :env option so the dependency is written to config/environments/test.rb: gem 'rspec', :env => 'test' gem 'quietbacktrace', :env => %w[development test] Signed-off-by: Pratik Naik --- .../generators/applications/app/template_runner.rb | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 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 eeb6b17661..d6e3ceeba9 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -85,6 +85,7 @@ module Rails # Adds an entry into config/environment.rb for the supplied gem : def gem(name, options = {}) log 'gem', name + env = options.delete(:env) gems_code = "config.gem '#{name}'" @@ -93,18 +94,26 @@ module Rails gems_code << ", #{opts}" end - environment gems_code + environment gems_code, :env => env end # Adds a line inside the Initializer block for config/environment.rb. Used by #gem - def environment(data = nil, &block) + # If options :env is specified, the line is appended to the corresponding + # file in config/environments/#{env}.rb + def environment(data = nil, options = {}, &block) sentinel = 'Rails::Initializer.run do |config|' data = block.call if !data && block_given? in_root do - gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n " << data + if options[:env].nil? + gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n " << data + end + else + options[:env].to_a.each do|env| + append_file "config/environments/#{env}.rb", "\n#{data}" + end end end end @@ -356,6 +365,17 @@ module Rails File.open(path, 'wb') { |file| file.write(content) } end + # Append text to a file + # + # ==== Example + # + # append_file 'config/environments/test.rb', 'config.gem "rspec"' + # + def append_file(relative_destination, data) + path = destination_path(relative_destination) + File.open(path, 'ab') { |file| file.write(data) } + end + def destination_path(relative_destination) File.join(root, relative_destination) end -- cgit v1.2.3 From 2686286a702e910b7fef520d901d6e95c1f4bd4b Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 28 Feb 2009 18:31:24 +0000 Subject: Ensure 16b3d2b621b1682f249209097c31b0a10f0f87ef works with Ruby 1.9 --- .../lib/rails_generator/generators/applications/app/template_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 d6e3ceeba9..a92747dd77 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -111,7 +111,7 @@ module Rails "#{match}\n " << data end else - options[:env].to_a.each do|env| + Array(options[:env]).each do|env| append_file "config/environments/#{env}.rb", "\n#{data}" end end -- cgit v1.2.3 From 5029210914059faa65358b98a9c033a40e803c54 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 28 Feb 2009 19:03:41 +0000 Subject: Use Array.wrap() instead of Array() and handle action_view.cache_template_loading being false --- .../lib/rails_generator/generators/applications/app/template_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 a92747dd77..efed030de0 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -111,7 +111,7 @@ module Rails "#{match}\n " << data end else - Array(options[:env]).each do|env| + Array.wrap(options[:env]).each do|env| append_file "config/environments/#{env}.rb", "\n#{data}" end end -- cgit v1.2.3 From 3b169cd693f45911ee71e26708fb9267811c8d83 Mon Sep 17 00:00:00 2001 From: Charles Nutter Date: Sat, 28 Feb 2009 17:47:00 -0600 Subject: Speed up script/console by launching IRB directly. [#2104 state:committed] Signed-off-by: Jeremy Kemper --- railties/lib/commands/console.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/console.rb b/railties/lib/commands/console.rb index 63df834639..45acd18c2f 100644 --- a/railties/lib/commands/console.rb +++ b/railties/lib/commands/console.rb @@ -1,26 +1,23 @@ -irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' - require 'optparse' -options = { :sandbox => false, :irb => irb } +options = { :sandbox => false } OptionParser.new do |opt| opt.banner = "Usage: console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } - opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v } opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v } opt.parse!(ARGV) end -libs = " -r irb/completion" -libs << %( -r "#{RAILS_ROOT}/config/environment") -libs << " -r console_app" -libs << " -r console_sandbox" if options[:sandbox] -libs << " -r console_with_helpers" +require 'irb' +require "irb/completion" +require "#{RAILS_ROOT}/config/environment" +require "console_app" +require "console_sandbox" if options[:sandbox] +require "console_with_helpers" if options[:debugger] begin require 'ruby-debug' - libs << " -r ruby-debug" puts "=> Debugger enabled" rescue Exception puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'" @@ -42,4 +39,6 @@ if options[:sandbox] else puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails.version})" end -exec "#{options[:irb]} #{libs} --simple-prompt" + +ARGV.replace(["--simple-prompt"]) +IRB.start -- cgit v1.2.3 From a3ac1e1621506a6519b265ef6ec6abc70f6c8a27 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Sun, 1 Mar 2009 11:53:58 +0000 Subject: Display gem dependencies correctly and unpack exactly once [#2097 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/rails/gem_dependency.rb | 11 +++++++---- railties/lib/tasks/gems.rake | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 5a07841be8..2dd659032f 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -72,13 +72,14 @@ module Rails rescue Gem::LoadError end - def dependencies - return [] if framework_gem? - return [] if specification.nil? + def dependencies(options = {}) + return [] if framework_gem? || specification.nil? + all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end - all_dependencies += all_dependencies.map(&:dependencies).flatten + + all_dependencies += all_dependencies.map { |d| d.dependencies(options) }.flatten if options[:flatten] all_dependencies.uniq end @@ -149,6 +150,8 @@ module Rails end def unpack_to(directory) + return if specification.nil? || File.directory?(gem_dir(directory)) || framework_gem? + FileUtils.mkdir_p directory Dir.chdir directory do Gem::GemRunner.new.run(unpack_command) diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index d538e52ca6..0932ba73b5 100644 --- a/railties/lib/tasks/gems.rake +++ b/railties/lib/tasks/gems.rake @@ -47,8 +47,8 @@ namespace :gems do require 'rubygems' require 'rubygems/gem_runner' Rails.configuration.gems.each do |gem| - next unless !gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name) - gem.unpack_to(Rails::GemDependency.unpacked_path) if gem.loaded? + next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name + gem.unpack_to(Rails::GemDependency.unpacked_path) end end @@ -59,8 +59,7 @@ namespace :gems do require 'rubygems/gem_runner' Rails.configuration.gems.each do |gem| next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name - gem.dependencies.each do |dependency| - next if dependency.frozen? + gem.dependencies(:flatten => true).each do |dependency| dependency.unpack_to(Rails::GemDependency.unpacked_path) end end -- cgit v1.2.3 From 04fdb6eccb3a49b26bdbf779031f427da23a8bb4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 1 Mar 2009 19:03:38 -0800 Subject: Revert "Speed up script/console by launching IRB directly." [#2104 state:open] This reverts commit 3b169cd693f45911ee71e26708fb9267811c8d83. --- railties/lib/commands/console.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/console.rb b/railties/lib/commands/console.rb index 45acd18c2f..63df834639 100644 --- a/railties/lib/commands/console.rb +++ b/railties/lib/commands/console.rb @@ -1,23 +1,26 @@ +irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' + require 'optparse' -options = { :sandbox => false } +options = { :sandbox => false, :irb => irb } OptionParser.new do |opt| opt.banner = "Usage: console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } + opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v } opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v } opt.parse!(ARGV) end -require 'irb' -require "irb/completion" -require "#{RAILS_ROOT}/config/environment" -require "console_app" -require "console_sandbox" if options[:sandbox] -require "console_with_helpers" +libs = " -r irb/completion" +libs << %( -r "#{RAILS_ROOT}/config/environment") +libs << " -r console_app" +libs << " -r console_sandbox" if options[:sandbox] +libs << " -r console_with_helpers" if options[:debugger] begin require 'ruby-debug' + libs << " -r ruby-debug" puts "=> Debugger enabled" rescue Exception puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'" @@ -39,6 +42,4 @@ if options[:sandbox] else puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails.version})" end - -ARGV.replace(["--simple-prompt"]) -IRB.start +exec "#{options[:irb]} #{libs} --simple-prompt" -- cgit v1.2.3 From 4d4d2c3896ed5a5d74da833c5c3132f406f4eab7 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Tue, 3 Mar 2009 12:39:19 -0600 Subject: Enhanced Rails Metal - the load order of metals can now be configured [#2057 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 6 ++++++ railties/lib/rails/rack/metal.rb | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 24ce3e75ff..edea4e513a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -559,6 +559,7 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal + Rails::Rack::Metal.requested_metals = configuration.metals Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths configuration.middleware.insert_before( @@ -715,6 +716,11 @@ Run `rake gems:install` to install the missing gems. @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } end + # The list of metals to load. If this is set to nil, all metals will + # be loaded in alphabetical order. If this is set to [], no metals will + # be loaded. Otherwise metals will be loaded in the order specified + attr_accessor :metals + # The path to the root of the plugins directory. By default, it is in # vendor/plugins. attr_accessor :plugin_paths diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 8dac992ef2..bce59f4c78 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -8,16 +8,26 @@ module Rails cattr_accessor :metal_paths self.metal_paths = ["#{Rails.root}/app/metal"] + cattr_accessor :requested_metals def self.metals matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } + all_metals = {} Dir[*metal_glob].sort.map do |file| - path = file.match(matcher)[1] - require path - path.classify.constantize + file = file.match(matcher)[1] + all_metals[file.classify] = file end + + load_list = requested_metals || all_metals.keys + + load_list.map do |requested_metal| + if metal = all_metals[requested_metal] + require metal + requested_metal.constantize + end + end.compact end def initialize(app) -- cgit v1.2.3 From de540416e9a1ead164c9c80352565de2dc5955ce Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 5 Mar 2009 12:22:42 +0100 Subject: Make sure that Rails frameworks are silenced when running in gem mode too --- railties/lib/rails/backtrace_cleaner.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index e1b422716d..b6fdf42c4e 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -2,6 +2,8 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ + RAILS_GEMS = %w( actionpack activerecord actionmailer activesupport activeresource rails ) + VENDOR_DIRS = %w( vendor/gems vendor/rails ) SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/passenger bin/passenger-spawn-server @@ -20,6 +22,7 @@ module Rails add_filter { |line| line.sub('./', '/') } # for tests add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } } add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } end end -- cgit v1.2.3 From e97180c273ada9b252ddf42d340d2947a509cb26 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Thu, 5 Mar 2009 18:50:52 -0600 Subject: Ensure that loading metals from the main app and engines works on older Ruby versions [#2143 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/rails/rack/metal.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index bce59f4c78..78b8a01449 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -15,9 +15,11 @@ module Rails metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } all_metals = {} - Dir[*metal_glob].sort.map do |file| - file = file.match(matcher)[1] - all_metals[file.classify] = file + metal_glob.each do |glob| + Dir[glob].sort.map do |file| + file = file.match(matcher)[1] + all_metals[file.classify] = file + end end load_list = requested_metals || all_metals.keys -- cgit v1.2.3 From 8bc0f90d6d5a6d653b9834e8bbca6ac20e25c293 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 6 Mar 2009 17:22:52 +0000 Subject: script/plugin install should remove .gitignore too. [#1306 state:resolved] [Esad Hajdarevic] --- railties/lib/commands/plugin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 9ff4739562..a67c2ab447 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -278,8 +278,8 @@ class Plugin base_cmd += " #{options[:revision]}" if options[:revision] puts base_cmd if $verbose if system(base_cmd) - puts "removing: .git" if $verbose - rm_rf ".git" + puts "removing: .git .gitignore" if $verbose + rm_rf %w(.git .gitignore) else rm_rf install_path end -- cgit v1.2.3 From 0da8e45baf592bf715023c0553b9aefd15b86579 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Thu, 5 Mar 2009 15:48:56 -0500 Subject: Correctly clean backtraces from vendor/gems and gems in alternate install locations Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/backtrace_cleaner.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index b6fdf42c4e..923ed8b31d 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -4,15 +4,13 @@ module Rails RAILS_GEMS = %w( actionpack activerecord actionmailer activesupport activeresource rails ) - VENDOR_DIRS = %w( vendor/gems vendor/rails ) + VENDOR_DIRS = %w( vendor/rails ) SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/passenger bin/passenger-spawn-server lib/rack ) RAILS_NOISE = %w( script/server ) RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) - GEMS_DIR = Gem.default_dir - ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE def initialize @@ -20,11 +18,25 @@ module Rails add_filter { |line| line.sub("#{RAILS_ROOT}/", '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } add_filter { |line| line.sub('./', '/') } # for tests - add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 + + add_gem_filters + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } } add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } end + + + private + def add_gem_filters + Gem.path.each do |path| + # http://gist.github.com/30430 + add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} + end + + vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'') + add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')} + end end # For installing the BacktraceCleaner in the test/unit -- cgit v1.2.3 From 1d88a111b596c046e67fd290de0a40161350332b Mon Sep 17 00:00:00 2001 From: Andrew Timberlake Date: Mon, 9 Mar 2009 14:58:12 +0000 Subject: Ensure TemplateRunner#ask? works with the rake task to apply a template [#1655 state:resolved] Signed-off-by: Pratik Naik --- .../lib/rails_generator/generators/applications/app/template_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 efed030de0..73ab57d4f0 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -316,7 +316,7 @@ module Rails # def ask(string) log '', string - gets.strip + STDIN.gets.strip end # Do something in the root of the Rails application or -- cgit v1.2.3 From 0c9bbf8c9dca46fbd7916640c417d13bf8b5af30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Mar 2009 23:31:04 -0500 Subject: Fix serving index files with rack static file server [#2180 state:resolved] --- railties/lib/rails/rack/static.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb index ef4e2642e2..f07c6beb5e 100644 --- a/railties/lib/rails/rack/static.rb +++ b/railties/lib/rails/rack/static.rb @@ -13,14 +13,18 @@ module Rails def call(env) path = env['PATH_INFO'].chomp('/') method = env['REQUEST_METHOD'] - cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension if FILE_METHODS.include?(method) if file_exist?(path) return @file_server.call(env) - elsif file_exist?(cached_path) - env['PATH_INFO'] = cached_path - return @file_server.call(env) + else + cached_path = directory_exist?(path) ? "#{path}/index" : path + cached_path += ::ActionController::Base.page_cache_extension + + if file_exist?(cached_path) + env['PATH_INFO'] = cached_path + return @file_server.call(env) + end end end @@ -32,6 +36,11 @@ module Rails full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path)) File.file?(full_path) && File.readable?(full_path) end + + def directory_exist?(path) + full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path)) + File.directory?(full_path) && File.readable?(full_path) + end end end end -- cgit v1.2.3 From e609d83f1a7f49bf8a9549c480a67ee045950336 Mon Sep 17 00:00:00 2001 From: Jeff Schwab Date: Thu, 5 Mar 2009 21:30:26 -0500 Subject: Fixed an incompatibility with Ruby 1.9. Ruby 1.8 strings are Enumerable, but there is no String#lines method. In Ruby 1.9, the situation is reversed. To work around this disparity, the RailsEnvironment#externals method now explicitly checks whether a String responds_to? :lines. [#2130 state:committed] Signed-off-by: Jeremy Kemper --- railties/lib/commands/plugin.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index a67c2ab447..8589b1698d 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -134,7 +134,8 @@ class RailsEnvironment def externals return [] unless use_externals? ext = `svn propget svn:externals "#{root}/vendor/plugins"` - ext.reject{ |line| line.strip == '' }.map do |line| + lines = ext.respond_to?(:lines) ? ext.lines : ext + lines.reject{ |line| line.strip == '' }.map do |line| line.strip.split(/\s+/, 2) end end -- cgit v1.2.3 From 8a17fd1a65ab8e2fa6b36d79603fde0e6ffd083f Mon Sep 17 00:00:00 2001 From: Damian Terentiev Date: Thu, 12 Mar 2009 14:45:55 +0000 Subject: Fixed that template runner gem method to output :lib => false correctly [#1940 state:resolved] Signed-off-by: Pratik Naik --- .../lib/rails_generator/generators/applications/app/template_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 73ab57d4f0..3b49b1fa92 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -90,7 +90,7 @@ module Rails gems_code = "config.gem '#{name}'" if options.any? - opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.sort.join(", ") + opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ") gems_code << ", #{opts}" end -- cgit v1.2.3 From 5b751ae0b3f6c10a1053e4a2e04fd92d228d787f Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Wed, 11 Mar 2009 17:53:21 -0700 Subject: Execute the appropriate gem command when using JRuby [#2215 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/rails/gem_dependency.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 2dd659032f..ea36f69f2f 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -236,7 +236,14 @@ module Rails private def gem_command - RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem' + case RUBY_PLATFORM + when /win32/ + 'gem.bat' + when /java/ + 'jruby -S gem' + else + 'gem' + end end def install_command -- cgit v1.2.3 From 99d75a7b02bf430a124b9c3e2515850959d78acf Mon Sep 17 00:00:00 2001 From: David Dollar Date: Fri, 13 Mar 2009 10:20:23 +0000 Subject: Makes the gem system understand development vs. runtime dependencies [#2195 state:resolved] The patch also fixes: * Fixes the chicken/egg problem present in the current gem system when gems are defined in the config that are not yet installed. * Remove the need to have hoe as a dependency of your production app. * Makes the gem 'unpacking' system a lot less fragile. Signed-off-by: Matt Jones Signed-off-by: Pratik Naik --- railties/lib/initializer.rb | 4 +- railties/lib/rails/gem_dependency.rb | 214 +++++++++++++++++++---------------- railties/lib/tasks/gems.rake | 78 ++++++------- 3 files changed, 152 insertions(+), 144 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index edea4e513a..a04405a7c2 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -301,7 +301,9 @@ module Rails end def load_gems - @configuration.gems.each { |gem| gem.load } + unless $gems_build_rake_task + @configuration.gems.each { |gem| gem.load } + end end def check_gem_dependencies diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index ea36f69f2f..3062a77104 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -7,8 +7,8 @@ module Gem end module Rails - class GemDependency - attr_accessor :lib, :source + class GemDependency < Gem::Dependency + attr_accessor :lib, :source, :dep def self.unpacked_path @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems') @@ -29,18 +29,6 @@ module Rails end end - def framework_gem? - @@framework_gems.has_key?(name) - end - - def vendor_rails? - Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty? - end - - def vendor_gem? - Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.include?(self.class.unpacked_path) - end - def initialize(name, options = {}) require 'rubygems' unless Object.const_defined?(:Gem) @@ -52,10 +40,11 @@ module Rails req = Gem::Requirement.default end - @dep = Gem::Dependency.new(name, req) @lib = options[:lib] @source = options[:source] @loaded = @frozen = @load_paths_added = false + + super(name, req) end def add_load_paths @@ -65,52 +54,74 @@ module Rails @load_paths_added = @loaded = @frozen = true return end - gem @dep + gem self @spec = Gem.loaded_specs[name] @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec @load_paths_added = true rescue Gem::LoadError end - def dependencies(options = {}) - return [] if framework_gem? || specification.nil? - - all_dependencies = specification.dependencies.map do |dependency| + def dependencies + return [] if framework_gem? + return [] unless installed? + specification.dependencies.reject do |dependency| + dependency.type == :development + end.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end + end - all_dependencies += all_dependencies.map { |d| d.dependencies(options) }.flatten if options[:flatten] - all_dependencies.uniq + def specification + # code repeated from Gem.activate. Find a matching spec, or the currently loaded version. + # error out if loaded version and requested version are incompatible. + @spec ||= begin + matches = Gem.source_index.search(self) + matches << @@framework_gems[name] if framework_gem? + if Gem.loaded_specs[name] then + # This gem is already loaded. If the currently loaded gem is not in the + # list of candidate gems, then we have a version conflict. + existing_spec = Gem.loaded_specs[name] + unless matches.any? { |spec| spec.version == existing_spec.version } then + raise Gem::Exception, + "can't activate #{@dep}, already activated #{existing_spec.full_name}" + end + # we're stuck with it, so change to match + version_requirements = Gem::Requirement.create("=#{existing_spec.version}") + existing_spec + else + # new load + matches.last + end + end end - def gem_dir(base_directory) - File.join(base_directory, specification.full_name) + def requirement + r = version_requirements + (r == Gem::Requirement.default) ? nil : r end - def spec_filename(base_directory) - File.join(gem_dir(base_directory), '.specification') + def built? + # TODO: If Rubygems ever gives us a way to detect this, we should use it + false end - def load - return if @loaded || @load_paths_added == false - require(@lib || name) unless @lib == false - @loaded = true - rescue LoadError - puts $!.to_s - $!.backtrace.each { |b| puts b } + def framework_gem? + @@framework_gems.has_key?(name) end - def name - @dep.name.to_s + def frozen? + @frozen ||= vendor_rails? || vendor_gem? end - def requirement - r = @dep.version_requirements - (r == Gem::Requirement.default) ? nil : r + def installed? + Gem.loaded_specs.keys.include?(name) end - def frozen? - @frozen ||= vendor_rails? || vendor_gem? + def load_paths_added? + # always try to add load paths - even if a gem is loaded, it may not + # be a compatible version (ie random_gem 0.4 is loaded and a later spec + # needs >= 0.5 - gem 'random_gem' will catch this and error out) + @load_paths_added end def loaded? @@ -136,48 +147,49 @@ module Rails end end - def load_paths_added? - # always try to add load paths - even if a gem is loaded, it may not - # be a compatible version (ie random_gem 0.4 is loaded and a later spec - # needs >= 0.5 - gem 'random_gem' will catch this and error out) - @load_paths_added + def vendor_rails? + Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty? end - def install - cmd = "#{gem_command} #{install_command.join(' ')}" - puts cmd - puts %x(#{cmd}) + def vendor_gem? + specification && File.exists?(unpacked_gem_directory) end - def unpack_to(directory) - return if specification.nil? || File.directory?(gem_dir(directory)) || framework_gem? - - FileUtils.mkdir_p directory - Dir.chdir directory do - Gem::GemRunner.new.run(unpack_command) + def build + require 'rails/gem_builder' + unless built? + return unless File.exists?(unpacked_specification_filename) + spec = YAML::load_file(unpacked_specification_filename) + Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions + puts "Built gem: '#{unpacked_gem_directory}'" end - - # Gem.activate changes the spec - get the original - real_spec = Gem::Specification.load(specification.loaded_from) - write_spec(directory, real_spec) - + dependencies.each { |dep| dep.build } end - def write_spec(directory, spec) - # copy the gem's specification into GEMDIR/.specification so that - # we can access information about the gem on deployment systems - # without having the gem installed - File.open(spec_filename(directory), 'w') do |file| - file.puts spec.to_yaml + def install + unless installed? + cmd = "#{gem_command} #{install_command.join(' ')}" + puts cmd + puts %x(#{cmd}) end end - def refresh_spec(directory) + def load + return if @loaded || @load_paths_added == false + require(@lib || name) unless @lib == false + @loaded = true + rescue LoadError + puts $!.to_s + $!.backtrace.each { |b| puts b } + end + + def refresh + Rails::VendorGemSourceIndex.silence_spec_warnings = true real_gems = Gem.source_index.installed_source_index exact_dep = Gem::Dependency.new(name, "= #{specification.version}") matches = real_gems.search(exact_dep) installed_spec = matches.first - if File.exist?(File.dirname(spec_filename(directory))) + if frozen? if installed_spec # we have a real copy # get a fresh spec - matches should only have one element @@ -185,11 +197,11 @@ module Rails # spec is the same as the copy from real_gems - Gem.activate changes # some of the fields real_spec = Gem::Specification.load(matches.first.loaded_from) - write_spec(directory, real_spec) + write_specification(real_spec) puts "Reloaded specification for #{name} from installed gems." else # the gem isn't installed locally - write out our current specs - write_spec(directory, specification) + write_specification(specification) puts "Gem #{name} not loaded locally - writing out current spec." end else @@ -201,40 +213,35 @@ module Rails end end - def ==(other) - self.name == other.name && self.requirement == other.requirement + def unpack(options={}) + unless frozen? || framework_gem? + FileUtils.mkdir_p unpack_base + Dir.chdir unpack_base do + Gem::GemRunner.new.run(unpack_command) + end + # Gem.activate changes the spec - get the original + real_spec = Gem::Specification.load(specification.loaded_from) + write_specification(real_spec) + end + dependencies.each { |dep| dep.unpack } if options[:recursive] end - alias_method :"eql?", :"==" - def hash - @dep.hash + def write_specification(spec) + # copy the gem's specification into GEMDIR/.specification so that + # we can access information about the gem on deployment systems + # without having the gem installed + File.open(unpacked_specification_filename, 'w') do |file| + file.puts spec.to_yaml + end end - def specification - # code repeated from Gem.activate. Find a matching spec, or the currently loaded version. - # error out if loaded version and requested version are incompatible. - @spec ||= begin - matches = Gem.source_index.search(@dep) - matches << @@framework_gems[name] if framework_gem? - if Gem.loaded_specs[name] then - # This gem is already loaded. If the currently loaded gem is not in the - # list of candidate gems, then we have a version conflict. - existing_spec = Gem.loaded_specs[name] - unless matches.any? { |spec| spec.version == existing_spec.version } then - raise Gem::Exception, - "can't activate #{@dep}, already activated #{existing_spec.full_name}" - end - # we're stuck with it, so change to match - @dep.version_requirements = Gem::Requirement.create("=#{existing_spec.version}") - existing_spec - else - # new load - matches.last - end - end + def ==(other) + self.name == other.name && self.requirement == other.requirement end + alias_method :"eql?", :"==" private + def gem_command case RUBY_PLATFORM when /win32/ @@ -258,5 +265,18 @@ module Rails cmd << "--version" << "= "+specification.version.to_s if requirement cmd end + + def unpack_base + Rails::GemDependency.unpacked_path + end + + def unpacked_gem_directory + File.join(unpack_base, specification.full_name) + end + + def unpacked_specification_filename + File.join(unpacked_gem_directory, '.specification') + end + end end diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index 0932ba73b5..ed07bf2016 100644 --- a/railties/lib/tasks/gems.rake +++ b/railties/lib/tasks/gems.rake @@ -9,71 +9,57 @@ task :gems => 'gems:base' do puts "R = Framework (loaded before rails starts)" end -def print_gem_status(gem, indent=1) - code = gem.loaded? ? (gem.frozen? ? (gem.framework_gem? ? "R" : "F") : "I") : " " - puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}" - gem.dependencies.each { |g| print_gem_status(g, indent+1)} if gem.loaded? -end - namespace :gems do task :base do $gems_rake_task = true + require 'rubygems' + require 'rubygems/gem_runner' Rake::Task[:environment].invoke end desc "Build any native extensions for unpacked gems" task :build do - $gems_rake_task = true - require 'rails/gem_builder' - Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |gem_dir| - spec_file = File.join(gem_dir, '.specification') - next unless File.exists?(spec_file) - specification = YAML::load_file(spec_file) - next unless ENV['GEM'].blank? || ENV['GEM'] == specification.name - Rails::GemBuilder.new(specification, gem_dir).build_extensions - puts "Built gem: '#{gem_dir}'" - end + $gems_build_rake_task = true + Rake::Task['gems:unpack'].invoke + current_gems.each &:build end - desc "Installs all required gems for this application." + desc "Installs all required gems." task :install => :base do - require 'rubygems' - require 'rubygems/gem_runner' - Rails.configuration.gems.each { |gem| gem.install unless gem.loaded? } + current_gems.each &:install end - desc "Unpacks the specified gem into vendor/gems." - task :unpack => :base do - require 'rubygems' - require 'rubygems/gem_runner' - Rails.configuration.gems.each do |gem| - next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name - gem.unpack_to(Rails::GemDependency.unpacked_path) - end + desc "Unpacks all required gems into vendor/gems." + task :unpack => :install do + current_gems.each &:unpack end namespace :unpack do - desc "Unpacks the specified gems and its dependencies into vendor/gems" - task :dependencies => :unpack do - require 'rubygems' - require 'rubygems/gem_runner' - Rails.configuration.gems.each do |gem| - next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name - gem.dependencies(:flatten => true).each do |dependency| - dependency.unpack_to(Rails::GemDependency.unpacked_path) - end - end + desc "Unpacks all required gems and their dependencies into vendor/gems." + task :dependencies => :install do + current_gems.each { |gem| gem.unpack(:recursive => true) } end end desc "Regenerate gem specifications in correct format." task :refresh_specs => :base do - require 'rubygems' - require 'rubygems/gem_runner' - Rails::VendorGemSourceIndex.silence_spec_warnings = true - Rails.configuration.gems.each do |gem| - next unless gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name) - gem.refresh_spec(Rails::GemDependency.unpacked_path) if gem.loaded? - end + current_gems.each &:refresh + end +end + +def current_gems + gems = Rails.configuration.gems + gems = gems.select { |gem| gem.name == ENV['GEM'] } unless ENV['GEM'].blank? + gems +end + +def print_gem_status(gem, indent=1) + code = case + when gem.framework_gem? then 'R' + when gem.frozen? then 'F' + when gem.installed? then 'I' + else ' ' end -end \ No newline at end of file + puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}" + gem.dependencies.each { |g| print_gem_status(g, indent+1) } +end -- cgit v1.2.3 From 5f10533949457e3797c8f0b51eb30a9268bceb4d Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Sun, 15 Mar 2009 18:41:21 -0500 Subject: Make sure Metal use ActionController class name conventions [#2242 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/rails/rack/metal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 78b8a01449..adc43da864 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -18,7 +18,7 @@ module Rails metal_glob.each do |glob| Dir[glob].sort.map do |file| file = file.match(matcher)[1] - all_metals[file.classify] = file + all_metals[file.camelize] = file end end -- cgit v1.2.3 From 73fc42cc0b5e94541480032c2941a50edd4080c2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Mar 2009 22:06:50 -0500 Subject: Prepare for final 2.3 release --- 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 fd38705e75..99c7516a65 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 = 3 - TINY = 1 + TINY = 2 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From 11f53db2167e5a199ac31c427dd45dd2362bf32a Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 18 Mar 2009 18:33:44 +0000 Subject: Remove outdated script/plugin options --- railties/lib/commands/plugin.rb | 435 +--------------------------------------- 1 file changed, 3 insertions(+), 432 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 8589b1698d..c6c9892fae 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -1,47 +1,8 @@ # Rails Plugin Manager. -# -# Listing available plugins: -# -# $ ./script/plugin list -# continuous_builder http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder -# asset_timestamping http://svn.aviditybytes.com/rails/plugins/asset_timestamping -# enumerations_mixin http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk -# calculations http://techno-weenie.net/svn/projects/calculations/ -# ... # # Installing plugins: # # $ ./script/plugin install continuous_builder asset_timestamping -# -# Finding Repositories: -# -# $ ./script/plugin discover -# -# Adding Repositories: -# -# $ ./script/plugin source http://svn.protocool.com/rails/plugins/ -# -# How it works: -# -# * Maintains a list of subversion repositories that are assumed to have -# a plugin directory structure. Manage them with the (source, unsource, -# and sources commands) -# -# * The discover command scrapes the following page for things that -# look like subversion repositories with plugins: -# http://wiki.rubyonrails.org/rails/pages/Plugins -# -# * Unless you specify that you want to use svn, script/plugin uses plain old -# HTTP for downloads. The following bullets are true if you specify -# that you want to use svn. -# -# * If `vendor/plugins` is under subversion control, the script will -# modify the svn:externals property and perform an update. You can -# use normal subversion commands to keep the plugins up to date. -# -# * Or, if `vendor/plugins` is not under subversion control, the -# plugin is pulled via `svn checkout` or `svn export` but looks -# exactly the same. # # Specifying revisions: # @@ -156,13 +117,13 @@ end class Plugin attr_reader :name, :uri - def initialize(uri, name=nil) + def initialize(uri, name = nil) @uri = uri guess_name(uri) end def self.find(name) - name =~ /\// ? new(name) : Repositories.instance.find_plugin(name) + new(name) end def to_s @@ -310,129 +271,6 @@ class Plugin end end -class Repositories - include Enumerable - - def initialize(cache_file = File.join(find_home, ".rails-plugin-sources")) - @cache_file = File.expand_path(cache_file) - load! - end - - def each(&block) - @repositories.each(&block) - end - - def add(uri) - unless find{|repo| repo.uri == uri } - @repositories.push(Repository.new(uri)).last - end - end - - def remove(uri) - @repositories.reject!{|repo| repo.uri == uri} - end - - def exist?(uri) - @repositories.detect{|repo| repo.uri == uri } - end - - def all - @repositories - end - - def find_plugin(name) - @repositories.each do |repo| - repo.each do |plugin| - return plugin if plugin.name == name - end - end - return nil - end - - def load! - contents = File.exist?(@cache_file) ? File.read(@cache_file) : defaults - contents = defaults if contents.empty? - @repositories = contents.split(/\n/).reject do |line| - line =~ /^\s*#/ or line =~ /^\s*$/ - end.map { |source| Repository.new(source.strip) } - end - - def save - File.open(@cache_file, 'w') do |f| - each do |repo| - f.write(repo.uri) - f.write("\n") - end - end - end - - def defaults - <<-DEFAULTS - http://dev.rubyonrails.com/svn/rails/plugins/ - DEFAULTS - end - - def find_home - ['HOME', 'USERPROFILE'].each do |homekey| - return ENV[homekey] if ENV[homekey] - end - if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] - return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" - end - begin - File.expand_path("~") - rescue StandardError => ex - if File::ALT_SEPARATOR - "C:/" - else - "/" - end - end - end - - def self.instance - @instance ||= Repositories.new - end - - def self.each(&block) - self.instance.each(&block) - end -end - -class Repository - include Enumerable - attr_reader :uri, :plugins - - def initialize(uri) - @uri = uri.chomp('/') << "/" - @plugins = nil - end - - def plugins - unless @plugins - if $verbose - puts "Discovering plugins in #{@uri}" - puts index - end - - @plugins = index.reject{ |line| line !~ /\/$/ } - @plugins.map! { |name| Plugin.new(File.join(@uri, name), name) } - end - - @plugins - end - - def each(&block) - plugins.each(&block) - end - - private - def index - @index ||= RecursiveHTTPFetcher.new(@uri).ls - end -end - - # load default environment and parse arguments require 'optparse' module Commands @@ -472,14 +310,8 @@ module Commands o.separator "" o.separator "COMMANDS" - o.separator " discover Discover plugin repositories." - o.separator " list List available plugins." o.separator " install Install plugin(s) from known repositories or URLs." - o.separator " update Update installed plugins." o.separator " remove Uninstall plugins." - o.separator " source Add a plugin source repository." - o.separator " unsource Remove a plugin repository." - o.separator " sources List currently configured plugin repositories." o.separator "" o.separator "EXAMPLES" @@ -491,20 +323,6 @@ module Commands o.separator " #{@script_name} install git://github.com/SomeGuy/my_awesome_plugin.git\n" o.separator " Install a plugin and add a svn:externals entry to vendor/plugins" o.separator " #{@script_name} install -x continuous_builder\n" - o.separator " List all available plugins:" - o.separator " #{@script_name} list\n" - o.separator " List plugins in the specified repository:" - o.separator " #{@script_name} list --source=http://dev.rubyonrails.com/svn/rails/plugins/\n" - o.separator " Discover and prompt to add new repositories:" - o.separator " #{@script_name} discover\n" - o.separator " Discover new repositories but just list them, don't add anything:" - o.separator " #{@script_name} discover -l\n" - o.separator " Add a new repository to the source list:" - o.separator " #{@script_name} source http://dev.rubyonrails.com/svn/rails/plugins/\n" - o.separator " Remove a repository from the source list:" - o.separator " #{@script_name} unsource http://dev.rubyonrails.com/svn/rails/plugins/\n" - o.separator " Show currently configured repositories:" - o.separator " #{@script_name} sources\n" end end @@ -513,7 +331,7 @@ module Commands options.parse!(general) command = general.shift - if command =~ /^(list|discover|install|source|unsource|sources|remove|update|info)$/ + if command =~ /^(install|remove)$/ command = Commands.const_get(command.capitalize).new(self) command.parse!(sub) else @@ -535,218 +353,6 @@ module Commands end end - - class List - def initialize(base_command) - @base_command = base_command - @sources = [] - @local = false - @remote = true - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} list [OPTIONS] [PATTERN]" - o.define_head "List available plugins." - o.separator "" - o.separator "Options:" - o.separator "" - o.on( "-s", "--source=URL1,URL2", Array, - "Use the specified plugin repositories.") {|sources| @sources = sources} - o.on( "--local", - "List locally installed plugins.") {|local| @local, @remote = local, false} - o.on( "--remote", - "List remotely available plugins. This is the default behavior", - "unless --local is provided.") {|remote| @remote = remote} - end - end - - def parse!(args) - options.order!(args) - unless @sources.empty? - @sources.map!{ |uri| Repository.new(uri) } - else - @sources = Repositories.instance.all - end - if @remote - @sources.map{|r| r.plugins}.flatten.each do |plugin| - if @local or !plugin.installed? - puts plugin.to_s - end - end - else - cd "#{@base_command.environment.root}/vendor/plugins" - Dir["*"].select{|p| File.directory?(p)}.each do |name| - puts name - end - end - end - end - - - class Sources - def initialize(base_command) - @base_command = base_command - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} sources [OPTIONS] [PATTERN]" - o.define_head "List configured plugin repositories." - o.separator "" - o.separator "Options:" - o.separator "" - o.on( "-c", "--check", - "Report status of repository.") { |sources| @sources = sources} - end - end - - def parse!(args) - options.parse!(args) - Repositories.each do |repo| - puts repo.uri - end - end - end - - - class Source - def initialize(base_command) - @base_command = base_command - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} source REPOSITORY [REPOSITORY [REPOSITORY]...]" - o.define_head "Add new repositories to the default search list." - end - end - - def parse!(args) - options.parse!(args) - count = 0 - args.each do |uri| - if Repositories.instance.add(uri) - puts "added: #{uri.ljust(50)}" if $verbose - count += 1 - else - puts "failed: #{uri.ljust(50)}" - end - end - Repositories.instance.save - puts "Added #{count} repositories." - end - end - - - class Unsource - def initialize(base_command) - @base_command = base_command - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} unsource URI [URI [URI]...]" - o.define_head "Remove repositories from the default search list." - o.separator "" - o.on_tail("-h", "--help", "Show this help message.") { puts o; exit } - end - end - - def parse!(args) - options.parse!(args) - count = 0 - args.each do |uri| - if Repositories.instance.remove(uri) - count += 1 - puts "removed: #{uri.ljust(50)}" - else - puts "failed: #{uri.ljust(50)}" - end - end - Repositories.instance.save - puts "Removed #{count} repositories." - end - end - - - class Discover - def initialize(base_command) - @base_command = base_command - @list = false - @prompt = true - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} discover URI [URI [URI]...]" - o.define_head "Discover repositories referenced on a page." - o.separator "" - o.separator "Options:" - o.separator "" - o.on( "-l", "--list", - "List but don't prompt or add discovered repositories.") { |list| @list, @prompt = list, !@list } - o.on( "-n", "--no-prompt", - "Add all new repositories without prompting.") { |v| @prompt = !v } - end - end - - def parse!(args) - options.parse!(args) - args = ['http://wiki.rubyonrails.org/rails/pages/Plugins'] if args.empty? - args.each do |uri| - scrape(uri) do |repo_uri| - catch(:next_uri) do - if @prompt - begin - $stdout.print "Add #{repo_uri}? [Y/n] " - throw :next_uri if $stdin.gets !~ /^y?$/i - rescue Interrupt - $stdout.puts - exit 1 - end - elsif @list - puts repo_uri - throw :next_uri - end - Repositories.instance.add(repo_uri) - puts "discovered: #{repo_uri}" if $verbose or !@prompt - end - end - end - Repositories.instance.save - end - - def scrape(uri) - require 'open-uri' - puts "Scraping #{uri}" if $verbose - dupes = [] - content = open(uri).each do |line| - begin - if line =~ /]*href=['"]([^'"]*)['"]/ || line =~ /(svn:\/\/[^<|\n]*)/ - uri = $1 - if uri =~ /^\w+:\/\// && uri =~ /\/plugins\// && uri !~ /\/browser\// && uri !~ /^http:\/\/wiki\.rubyonrails/ && uri !~ /http:\/\/instiki/ - uri = extract_repository_uri(uri) - yield uri unless dupes.include?(uri) || Repositories.instance.exist?(uri) - dupes << uri - end - end - rescue - puts "Problems scraping '#{uri}': #{$!.to_s}" - end - end - end - - def extract_repository_uri(uri) - uri.match(/(svn|https?):.*\/plugins\//i)[0] - end - end - class Install def initialize(base_command) @base_command = base_command @@ -817,41 +423,6 @@ module Commands end end - class Update - def initialize(base_command) - @base_command = base_command - end - - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} update [name [name]...]" - o.on( "-r REVISION", "--revision REVISION", - "Checks out the given revision from subversion.", - "Ignored if subversion is not used.") { |v| @revision = v } - o.define_head "Update plugins." - end - end - - def parse!(args) - options.parse!(args) - root = @base_command.environment.root - cd root - args = Dir["vendor/plugins/*"].map do |f| - File.directory?("#{f}/.svn") ? File.basename(f) : nil - end.compact if args.empty? - cd "vendor/plugins" - args.each do |name| - if File.directory?(name) - puts "Updating plugin: #{name}" - system("svn #{$verbose ? '' : '-q'} up \"#{name}\" #{@revision ? "-r #{@revision}" : ''}") - else - puts "Plugin doesn't exist: #{name}" - end - end - end - end - class Remove def initialize(base_command) @base_command = base_command -- cgit v1.2.3 From 93b98cb841a9b3224d0289a6aa65b2b76764fdf8 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 18 Mar 2009 18:39:31 +0000 Subject: Ensure script/plugin doesn't show error message when svn externals are not there --- railties/lib/commands/plugin.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index c6c9892fae..3d76bcc73f 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -169,10 +169,13 @@ class Plugin else puts "Plugin doesn't exist: #{path}" end - # clean up svn:externals - externals = rails_env.externals - externals.reject!{|n,u| name == n or name == u} - rails_env.externals = externals + + if rails_env.use_externals? + # clean up svn:externals + externals = rails_env.externals + externals.reject!{|n,u| name == n or name == u} + rails_env.externals = externals + end end def info -- cgit v1.2.3