From 334178722b8c33aba4acefe7f89e767a5660fc46 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 13 Nov 2008 21:06:11 -0800 Subject: Properly check silence_spec_warnings class variable [#1372 state:committed] Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/vendor_gem_source_index.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb index dc821693ac..5b7721f303 100644 --- a/railties/lib/rails/vendor_gem_source_index.rb +++ b/railties/lib/rails/vendor_gem_source_index.rb @@ -81,7 +81,7 @@ module Rails spec.files = files else $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+ - " Giving up.") unless @silence_spec_warnings + " Giving up.") unless @@silence_spec_warnings next end end @@ -137,4 +137,4 @@ module Rails end end -end \ No newline at end of file +end -- cgit v1.2.3 From 61e43700b85de753b6254893d5365e04d3465b9a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 14 Nov 2008 12:26:50 +0100 Subject: Prepare for RC2 --- railties/lib/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index a0986a2e05..bd835fba26 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -2,7 +2,7 @@ module Rails module VERSION #:nodoc: MAJOR = 2 MINOR = 2 - TINY = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From 51a19ae2bf33e66b23ff5c91bf584b2efa9e669f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Nov 2008 14:12:38 +0100 Subject: Assume that the next version is going to be 2.3 for now --- railties/lib/rails/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index bd835fba26..9bb4b2a96d 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -1,8 +1,8 @@ module Rails module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 - TINY = 1 + MINOR = 3 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From f42c77f927eb49b00e84d355e07de48723d03fcb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 22 Nov 2008 18:06:08 +0100 Subject: Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH] --- railties/lib/rails/backtrace_cleaner.rb | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 railties/lib/rails/backtrace_cleaner.rb (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb new file mode 100644 index 0000000000..ffc5ef42aa --- /dev/null +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -0,0 +1,34 @@ +module Rails + class BacktraceCleaner < ActiveSupport::BacktraceCleaner + ERB_METHOD_SIG = /:in `_run_erb_.*/ + + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + RAILS_NOISE = %w( script/server ) + RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) + + ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + + + def initialize + super + add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + end + end + + + # For installing the BacktraceCleaner in the test/unit + module BacktraceFilterForTestUnit #:nodoc: + def self.included(klass) + klass.send :alias_method_chain, :filter_backtrace, :cleaning + end + + def filter_backtrace_with_cleaning(backtrace) + backtrace = filter_backtrace_without_cleaning(backtrace) + backtrace = backtrace.first.split("\n") if backtrace.size == 1 + Rails.backtrace_cleaner.clean(backtrace) + end + end +end \ No newline at end of file -- cgit v1.2.3 From 0ecf2f6bdb7423516a18f45a65e1301cf8cd9c7d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 22 Nov 2008 14:00:58 -0600 Subject: Kill dead "new_mongrel" handler --- railties/lib/rails/mongrel_server/commands.rb | 342 -------------------------- railties/lib/rails/mongrel_server/handler.rb | 55 ----- 2 files changed, 397 deletions(-) delete mode 100644 railties/lib/rails/mongrel_server/commands.rb delete mode 100644 railties/lib/rails/mongrel_server/handler.rb (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/mongrel_server/commands.rb b/railties/lib/rails/mongrel_server/commands.rb deleted file mode 100644 index d29b18712f..0000000000 --- a/railties/lib/rails/mongrel_server/commands.rb +++ /dev/null @@ -1,342 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'optparse' -require 'yaml' -require 'etc' - -require 'mongrel' -require 'rails/mongrel_server/handler' - -module Rails - module MongrelServer - def self.send_signal(signal, pid_file) - pid = open(pid_file).read.to_i - print "Sending #{signal} to Mongrel at PID #{pid}..." - begin - Process.kill(signal, pid) - rescue Errno::ESRCH - puts "Process does not exist. Not running." - end - - puts "Done." - end - - class RailsConfigurator < Mongrel::Configurator - def setup_mime_types - mime = {} - - if defaults[:mime_map] - Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}") - mime = load_mime_map(defaults[:mime_map], mime) - end - - mime.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) } - end - - def mount_rails(prefix) - ENV['RAILS_ENV'] = defaults[:environment] - ::RAILS_ENV.replace(defaults[:environment]) if defined?(::RAILS_ENV) - - env_location = "#{defaults[:cwd]}/config/environment" - require env_location - - ActionController::Base.relative_url_root = defaults[:prefix] - uri prefix, :handler => Rails::MongrelServer::RailsHandler.new - end - end - - class Start < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"], - ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false], - ['-p', '--port PORT', "Which port to bind to", :@port, 3000], - ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"], - ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"], - ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "tmp/pids/mongrel.pid"], - ['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024], - ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60], - ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0], - ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil], - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, RAILS_ROOT], - ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"], - ['-B', '--debug', "Enable debugging mode", :@debug, false], - ['-C', '--config PATH', "Use a config file", :@config_file, nil], - ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil], - ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil], - ['', '--user USER', "User to run as", :@user, nil], - ['', '--group GROUP', "Group to run as", :@group, nil], - ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil], - - ['-b', '--binding ADDR', "Address to bind to (deprecated, use -a)", :@address, "0.0.0.0"], - ['-u', '--debugger', "Enable debugging mode (deprecated, use -B)", :@debug, false] - ] - end - - def validate - if @config_file - valid_exists?(@config_file, "Config file not there: #@config_file") - return false unless @valid - @config_file = File.expand_path(@config_file) - load_config - return false unless @valid - end - - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - # Change there to start, then we'll have to come back after daemonize - Dir.chdir(@cwd) - - valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix - valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file" - valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file" - valid_dir? @docroot, "Path to docroot not valid: #@docroot" - valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map - valid_exists? @config_file, "Config file not there: #@config_file" if @config_file - valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate - valid_user? @user if @user - valid_group? @group if @group - - return @valid - end - - def run - if @generate - @generate = File.expand_path(@generate) - Mongrel.log(:error, "** Writing config to \"#@generate\".") - open(@generate, "w") {|f| f.write(settings.to_yaml) } - Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.") - exit 0 - end - - config = RailsConfigurator.new(settings) do - defaults[:log] = $stdout if defaults[:environment] == 'development' - - Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}") - - unless defaults[:daemon] - Mongrel.log("=> Call with -d to detach") - Mongrel.log("=> Ctrl-C to shutdown server") - start_debugger if defaults[:debug] - end - - if defaults[:daemon] - if File.exist? defaults[:pid_file] - Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.") - Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.") - exit 1 - end - - daemonize - - Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.") - Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file - end - - Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log") - - listener do - prefix = defaults[:prefix] || '/' - - if defaults[:debug] - Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.") - debug(prefix) - end - - setup_mime_types - dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false) - dir_handler.passthrough_missing_files = true - - unless defaults[:environment] == 'production' - Mongrel.log("Mounting DirHandler at #{prefix}...") - uri prefix, :handler => dir_handler - end - - - Mongrel.log("Starting Rails with #{defaults[:environment]} environment...") - Mongrel.log("Mounting Rails at #{prefix}...") - mount_rails(prefix) - Mongrel.log("Rails loaded.") - - - Mongrel.log("Loading any Rails specific GemPlugins" ) - load_plugins - - if defaults[:config_script] - Mongrel.log("Loading #{defaults[:config_script]} external config script") - run_config(defaults[:config_script]) - end - - setup_signals - end - end - - config.run - Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}") - - if config.defaults[:daemon] - config.write_pid_file - else - Mongrel.log("Use CTRL-C to stop.") - tail "log/#{config.defaults[:environment]}.log" - end - - config.join - - if config.needs_restart - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ - cmd = "ruby #{__FILE__} start #{original_args.join(' ')}" - Mongrel.log("Restarting with arguments: #{cmd}") - config.stop(false, true) - config.remove_pid_file - - if config.defaults[:daemon] - system cmd - else - Mongrel.log(:error, "Can't restart unless in daemon mode.") - exit 1 - end - else - Mongrel.log("Win32 does not support restarts. Exiting.") - end - end - end - - def load_config - settings = {} - begin - settings = YAML.load_file(@config_file) - ensure - Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon] - end - - settings[:includes] ||= ["mongrel"] - - # Config file settings will override command line settings - settings.each do |key, value| - key = key.to_s - if config_keys.include?(key) - key = 'address' if key == 'host' - self.instance_variable_set("@#{key}", value) - else - failure "Unknown configuration setting: #{key}" - @valid = false - end - end - end - - def config_keys - @config_keys ||= - %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix) - end - - def settings - config_keys.inject({}) do |hash, key| - value = self.instance_variable_get("@#{key}") - key = 'host' if key == 'address' - hash[key.to_sym] ||= value - hash - end - end - - def start_debugger - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - Mongrel.log("=> Debugger enabled") - rescue Exception - Mongrel.log(:error, "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'") - exit - end - - def tail(log_file) - cursor = File.size(log_file) - last_checked = Time.now - tail_thread = Thread.new do - File.open(log_file, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end - tail_thread - end - end - - class Stop < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."], - ['-f', '--force', "Force the shutdown (kill -9).", :@force, false], - ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"], - ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - if @force - @wait.to_i.times do |waiting| - exit(0) if not File.exist? @pid_file - sleep 1 - end - - Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file - else - Mongrel::send_signal("TERM", @pid_file) - end - end - end - - - class Restart < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'], - ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - MongrelServer::send_signal("USR2", @pid_file) - end - end - end -end diff --git a/railties/lib/rails/mongrel_server/handler.rb b/railties/lib/rails/mongrel_server/handler.rb deleted file mode 100644 index a19eca7259..0000000000 --- a/railties/lib/rails/mongrel_server/handler.rb +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'mongrel' -require 'cgi' -require 'action_controller/dispatcher' - - -module Rails - module MongrelServer - # Implements a handler that can run Rails and serve files out of the - # Rails application's public directory. This lets you run your Rails - # application with Mongrel during development and testing, then use it - # also in production behind a server that's better at serving the - # static files. - # - # The RailsHandler takes a mime_map parameter which is a simple suffix=mimetype - # mapping that it should add to the list of valid mime types. - # - # It also supports page caching directly and will try to resolve a request - # in the following order: - # - # * If the requested exact PATH_INFO exists as a file then serve it. - # * If it exists at PATH_INFO+".html" exists then serve that. - # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispatch to have Rails go. - # - # This means that if you are using page caching it will actually work with Mongrel - # and you should see a decent speed boost (but not as fast as if you use a static - # server like Apache or Litespeed). - class RailsHandler < Mongrel::HttpHandler - # Construct a Mongrel::CGIWrapper and dispatch. - def process(request, response) - return if response.socket.closed? - - cgi = Mongrel::CGIWrapper.new(request, response) - cgi.handler = self - # We don't want the output to be really final until we're out of the lock - cgi.default_really_final = false - - ActionController::Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body) - - # This finalizes the output using the proper HttpResponse way - cgi.out("text/html",true) {""} - rescue Errno::EPIPE - response.socket.close - rescue Object => rails_error - STDERR.puts "#{Time.now.httpdate}: Error dispatching #{rails_error.inspect}" - STDERR.puts rails_error.backtrace.join("\n") - end - end - end -end -- cgit v1.2.3 From 1f48c09094610cbf26ec1e93d9bf978b2ae86fa8 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Mon, 24 Nov 2008 11:25:28 +0100 Subject: Accept a prefix argument to filter_backtrace_with_cleaning [#1456 state:committed] Add a prefix argument to filter_backtrace_with_cleaning so it has the same arity as test/unit's filter_backtrace. Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/backtrace_cleaner.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index ffc5ef42aa..88df0ebbda 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -1,14 +1,13 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ - + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) RAILS_NOISE = %w( script/server ) RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE - def initialize super @@ -18,15 +17,14 @@ module Rails end end - # For installing the BacktraceCleaner in the test/unit module BacktraceFilterForTestUnit #:nodoc: def self.included(klass) klass.send :alias_method_chain, :filter_backtrace, :cleaning end - - def filter_backtrace_with_cleaning(backtrace) - backtrace = filter_backtrace_without_cleaning(backtrace) + + def filter_backtrace_with_cleaning(backtrace, prefix=nil) + backtrace = filter_backtrace_without_cleaning(backtrace, prefix) backtrace = backtrace.first.split("\n") if backtrace.size == 1 Rails.backtrace_cleaner.clean(backtrace) end -- cgit v1.2.3 From 42b4407e35e8634370fb95dc6786d4fd0c0e6afa Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 24 Nov 2008 15:43:47 +0100 Subject: Strip out the ./ part of the test path so the backtrace align perfectly --- railties/lib/rails/backtrace_cleaner.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 88df0ebbda..82537d962f 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -13,6 +13,7 @@ module Rails super add_filter { |line| line.sub(RAILS_ROOT, '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_filter { |line| line.sub('./', '/') } # for tests add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } end end -- cgit v1.2.3 From c80fe1093deeb57eee8df11d3c4120158634cb81 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 25 Nov 2008 14:48:09 -0600 Subject: Move debugger into middleware --- railties/lib/rails/rack.rb | 1 + railties/lib/rails/rack/debugger.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 railties/lib/rails/rack/debugger.rb (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index b4f32c2d95..90535674e9 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,5 +1,6 @@ module Rails module Rack + autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :Static, "rails/rack/static" end diff --git a/railties/lib/rails/rack/debugger.rb b/railties/lib/rails/rack/debugger.rb new file mode 100644 index 0000000000..aa2711c616 --- /dev/null +++ b/railties/lib/rails/rack/debugger.rb @@ -0,0 +1,21 @@ +module Rails + module Rack + class Debugger + def initialize(app) + @app = app + + require_library_or_gem 'ruby-debug' + ::Debugger.start + ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings) + puts "=> Debugger enabled" + rescue Exception + puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" + exit + end + + def call(env) + @app.call(env) + end + end + end +end -- cgit v1.2.3 From 63d8f56774dcb1ea601928c3eb6c119d359fae10 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 14:41:20 +0100 Subject: Added app/[models|controllers|helpers] to the load path for plugins that has an app directory (go engines ;)) [DHH] --- railties/lib/rails/plugin.rb | 25 ++++++++++++++++++++++--- railties/lib/rails/plugin/loader.rb | 10 +++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 4d983843af..3b9e7dec2d 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -28,13 +28,17 @@ module Rails end def valid? - File.directory?(directory) && (has_lib_directory? || has_init_file?) + File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?) end # Returns a list of paths this plugin wishes to make available in $LOAD_PATH. def load_paths report_nonexistant_or_empty_plugin! unless valid? - has_lib_directory? ? [lib_path] : [] + + returning [] do |load_paths| + load_paths << lib_path if has_lib_directory? + load_paths << app_paths if has_app_directory? + end.flatten end # Evaluates a plugin's init.rb file. @@ -68,7 +72,16 @@ module Rails def report_nonexistant_or_empty_plugin! raise LoadError, "Can not find the plugin named: #{name}" - end + end + + + def app_paths + [ + File.join(directory, 'app', 'models'), + File.join(directory, 'app', 'controllers'), + File.join(directory, 'app', 'helpers') + ] + end def lib_path File.join(directory, 'lib') @@ -86,6 +99,11 @@ module Rails File.file?(gem_init_path) ? gem_init_path : classic_init_path end + + def has_app_directory? + File.directory?(File.join(directory, 'app')) + end + def has_lib_directory? File.directory?(lib_path) end @@ -94,6 +112,7 @@ module Rails File.file?(init_path) end + def evaluate_init_rb(initializer) if has_init_file? silence_warnings do diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 948d497007..8d7eac53c5 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -33,6 +33,7 @@ module Rails plugin.load(initializer) register_plugin_as_loaded(plugin) end + ensure_all_registered_plugins_are_loaded! end @@ -45,12 +46,15 @@ module Rails plugins.each do |plugin| plugin.load_paths.each do |path| $LOAD_PATH.insert(application_lib_index + 1, path) - ActiveSupport::Dependencies.load_paths << path + + ActiveSupport::Dependencies.load_paths << path + unless Rails.configuration.reload_plugins? ActiveSupport::Dependencies.load_once_paths << path end end end + $LOAD_PATH.uniq! end @@ -59,9 +63,9 @@ module Rails # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins - configuration.plugin_locators.map { |locator| + configuration.plugin_locators.map do |locator| locator.new(initializer).plugins - }.flatten + end.flatten # TODO: sorting based on config.plugins end -- cgit v1.2.3 From 4999d52e08a02ebba344f6c318f0af4b5b18f0e5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 20:03:25 +0100 Subject: Added that config/routes.rb files in engine plugins are automatically loaded (and reloaded when they change in dev mode) [DHH] --- railties/lib/rails/plugin.rb | 23 +++++++++++++++++++++-- railties/lib/rails/plugin/loader.rb | 17 ++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 3b9e7dec2d..2b1e877e2b 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -40,7 +40,7 @@ module Rails load_paths << app_paths if has_app_directory? end.flatten end - + # Evaluates a plugin's init.rb file. def load(initializer) return if loaded? @@ -60,7 +60,26 @@ module Rails def about @about ||= load_about_information end + + # Engines are plugins with an app/ directory. + def engine? + has_app_directory? + end + # Returns true if the engine ships with a routing file + def routed? + File.exist?(routing_file) + end + + def controller_path + File.join(directory, 'app', 'controllers') + end + + def routing_file + File.join(directory, 'config', 'routes.rb') + end + + private def load_about_information about_yml_path = File.join(@directory, "about.yml") @@ -82,7 +101,7 @@ module Rails File.join(directory, 'app', 'helpers') ] end - + def lib_path File.join(directory, 'lib') end diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 8d7eac53c5..ba3f67d1d0 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -22,6 +22,11 @@ module Rails @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) } end + # Returns the plugins that are in engine-form (have an app/ directory) + def engines + @engines ||= plugins.select(&:engine?) + end + # Returns all the plugins that could be found by the current locators. def all_plugins @all_plugins ||= locate_plugins @@ -56,7 +61,17 @@ module Rails end $LOAD_PATH.uniq! - end + end + + # Returns an array of all the controller paths found inside engine-type plugins. + def controller_paths + engines.collect(&:controller_path) + end + + def routing_files + engines.select(&:routed?).collect(&:routing_file) + end + protected -- cgit v1.2.3 From 3cc9d1c5ad1639283b43ee2b6099cb4f3b19bf23 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 20:30:21 +0100 Subject: Let all plugins not just engines have a config/routes.rb file --- railties/lib/rails/plugin/loader.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index ba3f67d1d0..f08d9b74e2 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -68,8 +68,9 @@ module Rails engines.collect(&:controller_path) end + # Returns an array of routing.rb files from all the plugins that include config/routes.rb def routing_files - engines.select(&:routed?).collect(&:routing_file) + plugins.select(&:routed?).collect(&:routing_file) end -- cgit v1.2.3 From f2ee056873b84f8917e72d87181e1a9f5f653342 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 18:59:24 +0100 Subject: Added view path support for engines [DHH] --- railties/lib/rails/plugin.rb | 11 ++++++----- railties/lib/rails/plugin/loader.rb | 34 ++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 2b1e877e2b..4901abe808 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -71,6 +71,11 @@ module Rails File.exist?(routing_file) end + + def view_path + File.join(directory, 'app', 'views') + end + def controller_path File.join(directory, 'app', 'controllers') end @@ -95,11 +100,7 @@ module Rails def app_paths - [ - File.join(directory, 'app', 'models'), - File.join(directory, 'app', 'controllers'), - File.join(directory, 'app', 'helpers') - ] + [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ] end def lib_path diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index f08d9b74e2..be81bdf4fa 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -39,6 +39,8 @@ module Rails register_plugin_as_loaded(plugin) end + configure_engines + ensure_all_registered_plugins_are_loaded! end @@ -63,19 +65,31 @@ module Rails $LOAD_PATH.uniq! end - # Returns an array of all the controller paths found inside engine-type plugins. - def controller_paths - engines.collect(&:controller_path) - end - - # Returns an array of routing.rb files from all the plugins that include config/routes.rb - def routing_files - plugins.select(&:routed?).collect(&:routing_file) - end - protected + def configure_engines + if engines.any? + add_engine_routing_configurations + add_engine_controller_paths + add_engine_view_paths + end + end + def add_engine_routing_configurations + engines.select(&:routed?).collect(&:routing_file).each do |routing_file| + ActionController::Routing::Routes.add_configuration_file(routing_file) + end + end + + def add_engine_controller_paths + ActionController::Routing.controller_paths += engines.collect(&:controller_path) + end + + def add_engine_view_paths + # reverse it such that the last engine can overwrite view paths from the first, like with routes + ActionController::Base.view_paths += ActionView::PathSet.new(engines.collect(&:view_path).reverse) + end + # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins -- cgit v1.2.3 From 1e8f9634f65e1076deba3e20cca3d032ec12e026 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 29 Nov 2008 10:45:52 +0100 Subject: Include Rack in the server noise --- railties/lib/rails/backtrace_cleaner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 82537d962f..d8626aaf14 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -3,11 +3,11 @@ module Rails ERB_METHOD_SIG = /:in `_run_erb_.*/ VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) - MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/rack ) RAILS_NOISE = %w( script/server ) RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) - ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE def initialize super -- cgit v1.2.3 From 3c07a8828ede3d41000513af29c293ae2e2a49d4 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 24 Nov 2008 23:07:12 -0500 Subject: handle missing dependecies in gem loading Signed-off-by: Michael Koziarski --- railties/lib/rails/gem_dependency.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index cd280ac023..5a07841be8 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -74,6 +74,7 @@ module Rails def dependencies return [] if framework_gem? + return [] if specification.nil? all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end -- cgit v1.2.3 From 0b4858cf38f522208381f9bfbbb5c066aceb30d2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 3 Dec 2008 10:23:58 -0600 Subject: Require rack/utils explicitly --- railties/lib/rails/rack/static.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb index 45eb0e5921..ef4e2642e2 100644 --- a/railties/lib/rails/rack/static.rb +++ b/railties/lib/rails/rack/static.rb @@ -1,3 +1,5 @@ +require 'rack/utils' + module Rails module Rack class Static -- cgit v1.2.3