From afde6fdd5ef3e6b0693a7e330777e85ef4cffddb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Oct 2011 12:59:33 -0500 Subject: Added X-Request-Id tracking and TaggedLogging to easily log that and other production concerns --- railties/lib/rails/application/bootstrap.rb | 4 ++-- railties/lib/rails/application/configuration.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 0aff05b681..c2cb121e42 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -24,12 +24,12 @@ module Rails initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin path = config.paths["log"].first - logger = ActiveSupport::BufferedLogger.new(path) + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(path)) logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) logger.auto_flushing = false if Rails.env.production? logger rescue StandardError - logger = ActiveSupport::BufferedLogger.new(STDERR) + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) logger.level = ActiveSupport::BufferedLogger::WARN logger.warn( "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 448521d2f0..8f5b28faf8 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, - :force_ssl, :helpers_paths, :logger, :preload_frameworks, + :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :whiny_nils -- cgit v1.2.3 From 010622bb989cb9fa3aac600a7fa7bcb894bb081a Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sat, 15 Oct 2011 17:20:54 +0800 Subject: On inpsect routes, show :controller and :action to indicate dynamic. --- railties/lib/rails/application/route_inspector.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8c6911e6bb..8252f21aa7 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -10,20 +10,21 @@ module Rails end routes = all_routes.collect do |route| + route_reqs = route.requirements - reqs = route.requirements.dup rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ - endpoint = rack_app ? rack_app.inspect : "#{reqs[:controller]}##{reqs[:action]}" - constraints = reqs.except(:controller, :action) + controller = route_reqs[:controller] || ':controller' + action = route_reqs[:action] || ':action' - reqs = endpoint == '#' ? '' : endpoint + endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}" + constraints = route_reqs.except(:controller, :action) - unless constraints.empty? - reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}" - end + reqs = endpoint + reqs += " #{constraints.inspect}" unless constraints.empty? verb = route.verb.source.gsub(/[$^]/, '') + {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs} end -- cgit v1.2.3 From 40b19e063592fc30705f17aafe6a458e7b622ff2 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 22 Nov 2011 23:26:27 +0100 Subject: Allow to change engine's loading priority with config.railties_order= --- railties/lib/rails/application/configuration.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8f5b28faf8..e95b0f5495 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -10,8 +10,8 @@ module Rails :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, - :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils + :ssl_options, :static_cache_control, :session_options, + :time_zone, :whiny_nils, :railties_order attr_writer :log_level attr_reader :encoding @@ -35,6 +35,7 @@ module Rails @middleware = app_middleware @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From 0cd3bf84068dd2b2d0bbb26062f2cdc7093a1b04 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 24 Nov 2011 01:45:50 +0100 Subject: Allow to display engine's routes when running `rake routes ENGINES=true` --- railties/lib/rails/application/route_inspector.rb | 37 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8252f21aa7..8da7de2584 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -4,12 +4,23 @@ module Rails # This class is just used for displaying route information when someone # executes `rake routes`. People should not use this class. class RouteInspector # :nodoc: + def initialize + @engines = ActiveSupport::OrderedHash.new + end + def format all_routes, filter = nil if filter all_routes = all_routes.select{ |route| route.defaults[:controller] == filter } end - routes = all_routes.collect do |route| + routes = collect_routes(all_routes) + + formatted_routes(routes) + + formatted_routes_for_engines + end + + def collect_routes(routes) + routes = routes.collect do |route| route_reqs = route.requirements rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ @@ -25,12 +36,32 @@ module Rails verb = route.verb.source.gsub(/[$^]/, '') - {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs} + collect_engine_routes(reqs, rack_app) + + {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs } end # Skip the route if it's internal info route - routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } + routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } + end + + def collect_engine_routes(name, rack_app) + return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes) + return if @engines[name] + + routes = rack_app.routes + if routes.is_a?(ActionDispatch::Routing::RouteSet) + @engines[name] = collect_routes(routes.routes) + end + end + + def formatted_routes_for_engines + @engines.map do |name, routes| + ["\nRoutes for #{name}:"] + formatted_routes(routes) + end.flatten + end + def formatted_routes(routes) name_width = routes.map{ |r| r[:name].length }.max verb_width = routes.map{ |r| r[:verb].length }.max path_width = routes.map{ |r| r[:path].length }.max -- cgit v1.2.3 From c9bb099318dd3bc293a6cb4672333147c1cce4b9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Nov 2011 12:42:11 +0100 Subject: Display mounted engines in `rake routes` by default --- railties/lib/rails/application/route_inspector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8da7de2584..26652a8e5e 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -46,7 +46,7 @@ module Rails end def collect_engine_routes(name, rack_app) - return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes) + return unless rack_app && rack_app.respond_to?(:routes) return if @engines[name] routes = rack_app.routes -- cgit v1.2.3 From 8ef1ec427f75a3ca2a2c19737a057ad3f354a9bd Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Mon, 10 Oct 2011 19:02:06 +0530 Subject: global variable `$rails_rake_task' not initialized Warning removed --- railties/lib/rails/application/finisher.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 028c8814c4..fc7d205a6f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -2,6 +2,7 @@ module Rails class Application module Finisher include Initializable + $rails_rake_task = nil initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) -- cgit v1.2.3 From 04ef93dae6d9cec616973c1110a33894ad4ba6ed Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 9 Dec 2011 16:03:18 -0800 Subject: * ActiveSupport::BufferedLogger#silence is deprecated. If you want to squelch logs for a certain block, change the log level for that block. * ActiveSupport::BufferedLogger#open_log is deprecated. This method should not have been public in the first place. * ActiveSupport::BufferedLogger's behavior of automatically creating the directory for your log file is deprecated. Please make sure to create the directory for your log file before instantiating. * ActiveSupport::BufferedLogger#auto_flushing is deprecated. Either set the sync level on the underlying file handle like this: f = File.open('foo.log', 'w') f.sync = true ActiveSupport::BufferedLogger.new f Or tune your filesystem. The FS cache is now what controls flushing. * ActiveSupport::BufferedLogger#flush is deprecated. Set sync on your filehandle, or tune your filesystem. --- railties/lib/rails/application/bootstrap.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index c2cb121e42..1ae90056d9 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -24,9 +24,18 @@ module Rails initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin path = config.paths["log"].first - logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(path)) + unless File.exist? File.dirname path + FileUtils.mkdir_p File.dirname path + end + + f = File.open path, 'w' + f.binmode + f.sync = !Rails.env.production? # make sure every write flushes + + logger = ActiveSupport::TaggedLogging.new( + ActiveSupport::BufferedLogger.new(f) + ) logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) - logger.auto_flushing = false if Rails.env.production? logger rescue StandardError logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) @@ -37,7 +46,6 @@ module Rails ) logger end - at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) } end # Initialize cache early in the stack so railties can make use of it. -- cgit v1.2.3 From 5c234ab8ed4659a74a6c47ce8337055a62f75eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 14:39:22 +0100 Subject: Composition > inheritance. --- railties/lib/rails/application/routes_reloader.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 1d1f5e1b06..c1f435a3ee 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,13 +1,21 @@ module Rails class Application - class RoutesReloader < ::ActiveSupport::FileUpdateChecker + class RoutesReloader attr_reader :route_sets - def initialize - super([]) { reload! } + def initialize(updater=ActiveSupport::FileUpdateChecker) + @updater = updater.new([]) { reload! } @route_sets = [] end + def paths + @updater.paths + end + + def execute_if_updated + @updater.execute_if_updated + end + def reload! clear! load_paths -- cgit v1.2.3 From 27f0add3f93510c1aee2491467dffbb1e4015bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 15:18:19 +0100 Subject: Improve docs for Rails::Application and add routes_reloader_hook and app_reloader_hooks. --- railties/lib/rails/application/bootstrap.rb | 7 ------ railties/lib/rails/application/finisher.rb | 36 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 1ae90056d9..e189009cc5 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -59,13 +59,6 @@ module Rails end end - initializer :set_clear_dependencies_hook, :group => :all do - ActionDispatch::Reloader.to_cleanup do - ActiveSupport::DescendantsTracker.clear - ActiveSupport::Dependencies.clear - end - end - # Sets the dependency loading mechanism. # TODO: Remove files from the $" and always use require. initializer :initialize_dependency_mechanism, :group => :all do diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index fc7d205a6f..df2853498a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -20,12 +20,6 @@ module Rails end end - initializer :add_to_prepare_blocks do - config.to_prepare_blocks.each do |block| - ActionDispatch::Reloader.to_prepare(&block) - end - end - initializer :add_builtin_route do |app| if Rails.env.development? app.routes.append do @@ -38,14 +32,22 @@ module Rails build_middleware_stack end - initializer :run_prepare_callbacks do - ActionDispatch::Reloader.prepare! - end - initializer :define_main_app_helper do |app| app.routes.define_mounted_helper(:main_app) end + initializer :add_to_prepare_blocks do + config.to_prepare_blocks.each do |block| + ActionDispatch::Reloader.to_prepare(&block) + end + end + + # This needs to happen before eager load so it happens + # in exactly the same point regardless of config.cache_classes + initializer :run_prepare_callbacks do + ActionDispatch::Reloader.prepare! + end + initializer :eager_load! do if config.cache_classes && !$rails_rake_task ActiveSupport.run_load_hooks(:before_eager_load, self) @@ -53,15 +55,21 @@ module Rails end end + # All initialization is done, including eager loading in production initializer :finisher_hook do ActiveSupport.run_load_hooks(:after_initialize, self) end - # Force routes to be loaded just at the end and add it to to_prepare callbacks - # This needs to be after the finisher hook to ensure routes added in the hook - # are still loaded. + # Set app reload just after the finisher hook to ensure + # paths added in the hook are still loaded. + initializer :set_clear_dependencies_hook, :group => :all do |app| + ActionDispatch::Reloader.to_cleanup(&app.app_reloader_hook) + end + + # Set app reload just after the finisher hook to ensure + # routes added in the hook are still loaded. initializer :set_routes_reloader do |app| - reloader = lambda { app.routes_reloader.execute_if_updated } + reloader = app.routes_reloader_hook reloader.call ActionDispatch::Reloader.to_prepare(&reloader) end -- cgit v1.2.3 From c2e3ce8d1e1174e66536d59d8d97eb2cc8ce6f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 15:34:31 +0100 Subject: Provide a unique point for running initializers. --- railties/lib/rails/application/configuration.rb | 3 ++- railties/lib/rails/application/finisher.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index e95b0f5495..9e1a5be358 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -11,7 +11,7 @@ module Rails :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils, :railties_order + :time_zone, :whiny_nils, :railties_order, :all_initializers attr_writer :log_level attr_reader :encoding @@ -36,6 +36,7 @@ module Rails @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] + @all_initializers = [] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index df2853498a..9c25e05ee5 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -4,6 +4,10 @@ module Rails include Initializable $rails_rake_task = nil + initializer :load_config_initializers do + config.all_initializers.each { |init| load(init) } + end + initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) end -- cgit v1.2.3 From c0466603288252a5db8a4d8cf0ca193004a542ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 16:23:50 +0100 Subject: Give hooks the flexibility to choose the type of callback. --- railties/lib/rails/application/finisher.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 9c25e05ee5..17e7aa0f28 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -66,16 +66,14 @@ module Rails # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_clear_dependencies_hook, :group => :all do |app| - ActionDispatch::Reloader.to_cleanup(&app.app_reloader_hook) + initializer :set_dependencies_hook, :group => :all do |app| + app.set_dependencies_hook end # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. - initializer :set_routes_reloader do |app| - reloader = app.routes_reloader_hook - reloader.call - ActionDispatch::Reloader.to_prepare(&reloader) + initializer :set_routes_reloader_hook do |app| + app.set_routes_reloader_hook end # Disable dependency loading during request cycle -- cgit v1.2.3 From 5266eb9f611a114663c48eec0680b7050181d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Oko=C5=84ski?= Date: Mon, 12 Dec 2011 16:52:56 +0100 Subject: Default relative_url_root to ENV["RAILS_RELATIVE_URL_ROOT"]. Fixes #3365 --- railties/lib/rails/application/configuration.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9e1a5be358..4b2afe3a28 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -9,7 +9,7 @@ module Rails :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, - :reload_plugins, :secret_token, :serve_static_assets, + :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :whiny_nils, :railties_order, :all_initializers @@ -37,6 +37,7 @@ module Rails @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] @all_initializers = [] + @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From fa1d9a884c0d5b70c97442e3360ac98ca5fa4340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 22:51:33 +0100 Subject: Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting `config.reload_classes_only_on_change` to false. Extensions like Active Record should add their respective files like db/schema.rb and db/structure.sql to `config.watchable_files` if they want their changes to affect classes reloading. Thanks to https://github.com/paneq/active_reload and Pastorino for the inspiration. <3 --- railties/lib/rails/application/configuration.rb | 49 ++++++++++++----------- railties/lib/rails/application/finisher.rb | 14 +++---- railties/lib/rails/application/routes_reloader.rb | 12 ++---- 3 files changed, 36 insertions(+), 39 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 4b2afe3a28..39d66ecc31 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -7,11 +7,11 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :filter_parameters, - :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, - :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, - :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils, :railties_order, :all_initializers + :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, + :initializers_paths, :logger, :log_tags, :preload_frameworks, + :railties_order, :relative_url_root, :reload_plugins, :secret_token, + :serve_static_assets, :ssl_options, :static_cache_control, :session_options, + :time_zone, :reload_classes_only_on_change, :whiny_nils attr_writer :log_level attr_reader :encoding @@ -19,25 +19,26 @@ module Rails def initialize(*) super self.encoding = "utf-8" - @allow_concurrency = false - @consider_all_requests_local = false - @filter_parameters = [] - @helpers_paths = [] - @dependency_loading = true - @serve_static_assets = true - @static_cache_control = nil - @force_ssl = false - @ssl_options = {} - @session_store = :cookie_store - @session_options = {} - @time_zone = "UTC" - @log_level = nil - @middleware = app_middleware - @generators = app_generators - @cache_store = [ :file_store, "#{root}/tmp/cache/" ] - @railties_order = [:all] - @all_initializers = [] - @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] + @allow_concurrency = false + @consider_all_requests_local = false + @filter_parameters = [] + @helpers_paths = [] + @dependency_loading = true + @serve_static_assets = true + @static_cache_control = nil + @force_ssl = false + @ssl_options = {} + @session_store = :cookie_store + @session_options = {} + @time_zone = "UTC" + @log_level = nil + @middleware = app_middleware + @generators = app_generators + @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] + @initializers_paths = [] + @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] + @reload_classes_only_on_change = true @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 17e7aa0f28..e000f6ef3a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -5,7 +5,7 @@ module Rails $rails_rake_task = nil initializer :load_config_initializers do - config.all_initializers.each { |init| load(init) } + config.initializers_paths.each { |init| load(init) } end initializer :add_generator_templates do @@ -64,18 +64,18 @@ module Rails ActiveSupport.run_load_hooks(:after_initialize, self) end - # Set app reload just after the finisher hook to ensure - # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do |app| - app.set_dependencies_hook - end - # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. initializer :set_routes_reloader_hook do |app| app.set_routes_reloader_hook end + # Set app reload just after the finisher hook to ensure + # paths added in the hook are still loaded. + initializer :set_dependencies_hook, :group => :all do |app| + app.set_dependencies_hook + end + # Disable dependency loading during request cycle initializer :disable_dependency_loading do if config.cache_classes && !config.dependency_loading diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index c1f435a3ee..460b84dfd9 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,21 +1,17 @@ +require "active_support/core_ext/module/delegation" + module Rails class Application class RoutesReloader attr_reader :route_sets + delegate :paths, :execute_if_updated, :updated?, :to => :@updater + def initialize(updater=ActiveSupport::FileUpdateChecker) @updater = updater.new([]) { reload! } @route_sets = [] end - def paths - @updater.paths - end - - def execute_if_updated - @updater.execute_if_updated - end - def reload! clear! load_paths -- cgit v1.2.3 From 11aa167e239a85513d00a7910446bedf7b1f7800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 08:49:04 +0100 Subject: Revert "Provide a unique point for running initializers." This reverts commit c2e3ce8d1e1174e66536d59d8d97eb2cc8ce6f25. Conflicts: railties/lib/rails/application/configuration.rb railties/lib/rails/application/finisher.rb railties/lib/rails/engine.rb --- railties/lib/rails/application/configuration.rb | 3 +-- railties/lib/rails/application/finisher.rb | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 39d66ecc31..40deecea1c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, - :initializers_paths, :logger, :log_tags, :preload_frameworks, + :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :whiny_nils @@ -36,7 +36,6 @@ module Rails @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] - @initializers_paths = [] @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index e000f6ef3a..3a94311b57 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -4,10 +4,6 @@ module Rails include Initializable $rails_rake_task = nil - initializer :load_config_initializers do - config.initializers_paths.each { |init| load(init) } - end - initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) end -- cgit v1.2.3 From cd3033eb627f408b71a7adf98c350e2c01115c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 09:19:58 +0100 Subject: Add config.file_watcher so developers can provide their own watchers (for instance, hooking on fsevents). --- railties/lib/rails/application/configuration.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 40deecea1c..dddf7e498f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/string/encoding' require 'active_support/core_ext/kernel/reporting' +require 'active_support/file_update_checker' require 'rails/engine/configuration' module Rails @@ -7,8 +8,8 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, - :logger, :log_tags, :preload_frameworks, + :dependency_loading, :file_watcher, :filter_parameters, + :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :whiny_nils @@ -38,6 +39,7 @@ module Rails @railties_order = [:all] @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true + @file_watcher = ActiveSupport::FileUpdateChecker @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From 693d2be82706d7dc40af6860a26330c49c27f151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 09:25:12 +0100 Subject: Move hooks back to initializers (we need an API that allows hooks to be replaced). --- railties/lib/rails/application/finisher.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 3a94311b57..738fb93994 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -62,14 +62,31 @@ module Rails # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. - initializer :set_routes_reloader_hook do |app| - app.set_routes_reloader_hook + initializer :set_routes_reloader_hook do + reloader = routes_reloader + hook = lambda { reloader.execute_if_updated } + hook.call + self.reloaders << reloader + ActionDispatch::Reloader.to_prepare(&hook) end # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do |app| - app.set_dependencies_hook + initializer :set_dependencies_hook, :group => :all do + callback = lambda do + ActiveSupport::DescendantsTracker.clear + ActiveSupport::Dependencies.clear + end + + if config.reload_classes_only_on_change + reloader = config.file_watcher.new(watchable_args, true, &callback) + self.reloaders << reloader + # We need to set a to_prepare callback regardless of the reloader result, i.e. + # models should be reloaded if any of the reloaders (i18n, routes) were updated. + ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) + else + ActionDispatch::Reloader.to_cleanup(&callback) + end end # Disable dependency loading during request cycle -- cgit v1.2.3 From 1f5b9bbdb377c1b0e29650a103bf53526ceefdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 10:07:02 +0100 Subject: Clean up FileUpdateChecker API. --- railties/lib/rails/application/finisher.rb | 2 +- railties/lib/rails/application/routes_reloader.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 738fb93994..064723c1e0 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -83,7 +83,7 @@ module Rails self.reloaders << reloader # We need to set a to_prepare callback regardless of the reloader result, i.e. # models should be reloaded if any of the reloaders (i18n, routes) were updated. - ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) + ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute } else ActionDispatch::Reloader.to_cleanup(&callback) end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 460b84dfd9..e080481976 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -3,12 +3,12 @@ require "active_support/core_ext/module/delegation" module Rails class Application class RoutesReloader - attr_reader :route_sets - - delegate :paths, :execute_if_updated, :updated?, :to => :@updater + attr_reader :route_sets, :paths + delegate :execute_if_updated, :updated?, :to => :@updater def initialize(updater=ActiveSupport::FileUpdateChecker) - @updater = updater.new([]) { reload! } + @paths = [] + @updater = updater.new(paths) { reload! } @route_sets = [] end -- cgit v1.2.3 From 80256abb39332dd49996b909d6f0413a15291a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 11:23:21 +0100 Subject: FileUpdateChecker should be able to handle deleted files. --- railties/lib/rails/application/finisher.rb | 7 +++---- railties/lib/rails/application/routes_reloader.rb | 15 +++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 064723c1e0..2ce2980b97 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -64,10 +64,9 @@ module Rails # routes added in the hook are still loaded. initializer :set_routes_reloader_hook do reloader = routes_reloader - hook = lambda { reloader.execute_if_updated } - hook.call + reloader.execute_if_updated self.reloaders << reloader - ActionDispatch::Reloader.to_prepare(&hook) + ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated } end # Set app reload just after the finisher hook to ensure @@ -79,7 +78,7 @@ module Rails end if config.reload_classes_only_on_change - reloader = config.file_watcher.new(watchable_args, true, &callback) + reloader = config.file_watcher.new(*watchable_args, &callback) self.reloaders << reloader # We need to set a to_prepare callback regardless of the reloader result, i.e. # models should be reloaded if any of the reloaders (i18n, routes) were updated. diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index e080481976..ef7e733ce4 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -4,11 +4,10 @@ module Rails class Application class RoutesReloader attr_reader :route_sets, :paths - delegate :execute_if_updated, :updated?, :to => :@updater + delegate :execute_if_updated, :execute, :updated?, :to => :updater - def initialize(updater=ActiveSupport::FileUpdateChecker) + def initialize @paths = [] - @updater = updater.new(paths) { reload! } @route_sets = [] end @@ -20,7 +19,15 @@ module Rails revert end - protected + private + + def updater + @updater ||= begin + updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! } + updater.execute + updater + end + end def clear! route_sets.each do |routes| -- cgit v1.2.3 From 283a08763495a6b3ce0b196259ee1666f2b08cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 18:48:10 +0100 Subject: Clean up the cache before the request in case we are running in the reload_classes_only_on_change schema. --- railties/lib/rails/application/finisher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 2ce2980b97..b9944bed26 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -71,7 +71,7 @@ module Rails # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do + initializer :set_clear_dependencies_hook, :group => :all do callback = lambda do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear -- cgit v1.2.3 From 02127e64061fc61868f085102277ac5b679e0f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:41:05 +0100 Subject: Allow a custom exceptions app to set. --- railties/lib/rails/application/configuration.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index dddf7e498f..a782441a21 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :file_watcher, :filter_parameters, + :dependency_loading, :exceptions_app, :file_watcher, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, @@ -40,6 +40,7 @@ module Rails @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true @file_watcher = ActiveSupport::FileUpdateChecker + @exceptions_app = nil @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From 572c3d517899524c2a7c4c84ad9646660168d4cd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Dec 2011 18:41:37 -0800 Subject: * BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger from Ruby stdlib. --- railties/lib/rails/application/bootstrap.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index e189009cc5..78d2e6c913 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -33,13 +33,13 @@ module Rails f.sync = !Rails.env.production? # make sure every write flushes logger = ActiveSupport::TaggedLogging.new( - ActiveSupport::BufferedLogger.new(f) + ActiveSupport::Logger.new(f) ) - logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) + logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase) logger rescue StandardError - logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) - logger.level = ActiveSupport::BufferedLogger::WARN + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR)) + logger.level = ActiveSupport::Logger::WARN logger.warn( "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." -- cgit v1.2.3 From 4f6af26a886630c97865a2e5023a9560692e6aa4 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Tue, 20 Dec 2011 22:18:23 +0300 Subject: remove AS whiny nil extension and deprecate config.whiny_nils --- railties/lib/rails/application/configuration.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a782441a21..d14cf737d9 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -12,7 +12,7 @@ module Rails :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :reload_classes_only_on_change, :whiny_nils + :time_zone, :reload_classes_only_on_change attr_writer :log_level attr_reader :encoding @@ -145,6 +145,11 @@ module Rails @session_options = args.shift || {} end end + + def whiny_nils=(*) + ActiveSupport::Deprecation.warn "config.whiny_nils option " \ + "is deprecated and no longer works", caller + end end end end -- cgit v1.2.3 From 5ca86ac8f924b333a5a01a47cc07cbcf39c16e80 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sat, 24 Dec 2011 15:57:54 +0300 Subject: deprecate String#encoding_aware? and remove its usage --- railties/lib/rails/application/configuration.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index d14cf737d9..79b12ad4eb 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -65,17 +65,9 @@ module Rails def encoding=(value) @encoding = value - if "ruby".encoding_aware? - silence_warnings do - Encoding.default_external = value - Encoding.default_internal = value - end - else - $KCODE = value - if $KCODE == "NONE" - raise "The value you specified for config.encoding is " \ - "invalid. The possible values are UTF8, SJIS, or EUC" - end + silence_warnings do + Encoding.default_external = value + Encoding.default_internal = value end end -- cgit v1.2.3 From 28cd098d99c52486aecb72aab39105d8abcd52ad Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 11:31:22 +0100 Subject: Correctly display rack apps with dynamic constraints in RoutesInspector If you used dynamic constraint like that: scope :constraint => MyConstraint.new do mount RackApp => "/foo" end routes were not displayed correctly when using `rake routes`. This commit fixes it. If you want nice display of dynamic constraints in `rake routes` output, please just override to_s method in your constraint's class. --- railties/lib/rails/application/route_inspector.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 26652a8e5e..3e08b78221 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -23,7 +23,7 @@ module Rails routes = routes.collect do |route| route_reqs = route.requirements - rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ + rack_app = discover_rack_app(route.app) controller = route_reqs[:controller] || ':controller' action = route_reqs[:action] || ':action' @@ -70,6 +70,15 @@ module Rails "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end + + def discover_rack_app(app) + class_name = app.class.name.to_s + if class_name == "ActionDispatch::Routing::Mapper::Constraints" + discover_rack_app(app.app) + elsif class_name !~ /^ActionDispatch::Routing/ + app + end + end end end end -- cgit v1.2.3 From 9fffef5f463d3c1f518373423c9e2044836b0de6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 16:16:17 +0100 Subject: Refactor RouteInspector --- railties/lib/rails/application/route_inspector.rb | 101 +++++++++++++++------- 1 file changed, 69 insertions(+), 32 deletions(-) (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 3e08b78221..5ca366c5f2 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -1,5 +1,64 @@ +require 'delegate' + module Rails class Application + class RouteWrapper < SimpleDelegator + def endpoint + rack_app ? rack_app.inspect : "#{controller}##{action}" + end + + def constraints + requirements.except(:controller, :action) + end + + def rack_app(app = self.app) + @rack_app ||= begin + class_name = app.class.name.to_s + if class_name == "ActionDispatch::Routing::Mapper::Constraints" + rack_app(app.app) + elsif class_name !~ /^ActionDispatch::Routing/ + app + end + end + end + + def verb + super.source.gsub(/[$^]/, '') + end + + def path + super.spec.to_s + end + + def name + super.to_s + end + + def reqs + @reqs ||= begin + reqs = endpoint + reqs += " #{constraints.inspect}" unless constraints.empty? + reqs + end + end + + def controller + requirements[:controller] || ':controller' + end + + def action + requirements[:action] || ':action' + end + + def internal? + path =~ %r{/rails/info/properties|^/assets} + end + + def engine? + rack_app && rack_app.respond_to?(:routes) + end + end + ## # This class is just used for displaying route information when someone # executes `rake routes`. People should not use this class. @@ -21,35 +80,22 @@ module Rails def collect_routes(routes) routes = routes.collect do |route| - route_reqs = route.requirements - - rack_app = discover_rack_app(route.app) - - controller = route_reqs[:controller] || ':controller' - action = route_reqs[:action] || ':action' + RouteWrapper.new(route) + end.reject do |route| + route.internal? + end.collect do |route| + collect_engine_routes(route) - endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}" - constraints = route_reqs.except(:controller, :action) - - reqs = endpoint - reqs += " #{constraints.inspect}" unless constraints.empty? - - verb = route.verb.source.gsub(/[$^]/, '') - - collect_engine_routes(reqs, rack_app) - - {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs } + {:name => route.name, :verb => route.verb, :path => route.path, :reqs => route.reqs } end - - # Skip the route if it's internal info route - routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } end - def collect_engine_routes(name, rack_app) - return unless rack_app && rack_app.respond_to?(:routes) + def collect_engine_routes(route) + name = route.endpoint + return unless route.engine? return if @engines[name] - routes = rack_app.routes + routes = route.rack_app.routes if routes.is_a?(ActionDispatch::Routing::RouteSet) @engines[name] = collect_routes(routes.routes) end @@ -70,15 +116,6 @@ module Rails "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end - - def discover_rack_app(app) - class_name = app.class.name.to_s - if class_name == "ActionDispatch::Routing::Mapper::Constraints" - discover_rack_app(app.app) - elsif class_name !~ /^ActionDispatch::Routing/ - app - end - end end end end -- cgit v1.2.3