diff options
Diffstat (limited to 'railties/lib/rails/application')
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 17 | ||||
-rw-r--r-- | railties/lib/rails/application/configurable.rb | 19 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 65 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 19 | ||||
-rw-r--r-- | railties/lib/rails/application/railties.rb | 30 | ||||
-rw-r--r-- | railties/lib/rails/application/routes_reloader.rb | 45 |
6 files changed, 101 insertions, 94 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 44e26b5713..9c9d85eed6 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -6,10 +6,7 @@ module Rails module Bootstrap include Initializable - initializer :load_environment_config do - environment = config.paths.config.environments.to_a.first - require environment if environment - end + initializer :load_environment_hook do end initializer :load_active_support do require 'active_support/dependencies' @@ -26,7 +23,7 @@ module Rails # Initialize the logger early in the stack in case we need to log some deprecation. initializer :initialize_logger do Rails.logger ||= config.logger || begin - path = config.paths.log.to_a.first + path = config.paths["log"].first logger = ActiveSupport::BufferedLogger.new(path) logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) logger.auto_flushing = false if Rails.env.production? @@ -54,11 +51,9 @@ module Rails end initializer :set_clear_dependencies_hook do - unless config.cache_classes - ActionDispatch::Callbacks.after do - ActiveSupport::DescendantsTracker.clear - ActiveSupport::Dependencies.clear - end + ActionDispatch::Reloader.to_cleanup do + ActiveSupport::DescendantsTracker.clear + ActiveSupport::Dependencies.clear end end @@ -73,4 +68,4 @@ module Rails end end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/application/configurable.rb b/railties/lib/rails/application/configurable.rb deleted file mode 100644 index f598e33965..0000000000 --- a/railties/lib/rails/application/configurable.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Rails - class Application - module Configurable - def self.included(base) - base.extend ClassMethods - end - - module ClassMethods - def inherited(base) - raise "You cannot inherit from a Rails::Application child" - end - end - - def config - @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) - end - end - end -end
\ No newline at end of file diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 465851c0e6..c74bcbedf2 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,31 +1,37 @@ -require 'active_support/deprecation' require 'active_support/core_ext/string/encoding' require 'rails/engine/configuration' module Rails class Application class Configuration < ::Rails::Engine::Configuration - include ::Rails::Configuration::Deprecated - - attr_accessor :allow_concurrency, :cache_classes, :cache_store, + attr_accessor :allow_concurrency, :asset_host, :cache_classes, :cache_store, :encoding, :consider_all_requests_local, :dependency_loading, - :filter_parameters, :log_level, :logger, :middleware, - :plugins, :preload_frameworks, :reload_plugins, + :filter_parameters, :helpers_paths, :logger, + :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :session_options, :time_zone, :whiny_nils + attr_writer :log_level + def initialize(*) super - @allow_concurrency = false + self.encoding = "utf-8" + @allow_concurrency = false @consider_all_requests_local = false - @encoding = "utf-8" - @filter_parameters = [] - @dependency_loading = true - @serve_static_assets = true - @session_store = :cookie_store - @session_options = {} - @time_zone = "UTC" - @middleware = app_middleware + @filter_parameters = [] + @helpers_paths = [] + @dependency_loading = true + @serve_static_assets = true + @session_store = :cookie_store + @session_options = {} + @time_zone = "UTC" + @log_level = nil + @middleware = app_middleware + @generators = app_generators + end + + def compiled_asset_path + "/" end def encoding=(value) @@ -45,23 +51,12 @@ module Rails def paths @paths ||= begin paths = super - paths.app.controllers << builtin_controller if builtin_controller - paths.config.database "config/database.yml" - paths.config.environment "config/environment.rb" - paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" - paths.lib.templates "lib/templates" - paths.log "log/#{Rails.env}.log" - paths.tmp "tmp" - paths.tmp.cache "tmp/cache" - paths.vendor "vendor", :load_path => true - paths.vendor.plugins "vendor/plugins" - - if File.exists?("#{root}/test/mocks/#{Rails.env}") - ActiveSupport::Deprecation.warn "\"Rails.root/test/mocks/#{Rails.env}\" won't be added " << - "automatically to load paths anymore in future releases" - paths.mocks_path "test/mocks", :autoload => true, :glob => Rails.env - end - + paths.add "config/database", :with => "config/database.yml" + paths.add "config/environment", :with => "config/environment.rb" + paths.add "lib/templates" + paths.add "log", :with => "log/#{Rails.env}.log" + paths.add "tmp" + paths.add "tmp/cache" paths end end @@ -83,7 +78,7 @@ module Rails # YAML::load. def database_configuration require 'erb' - YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result) + YAML::load(ERB.new(IO.read(paths["config/database"].first)).result) end def cache_store @@ -96,10 +91,6 @@ module Rails end end - def builtin_controller - File.expand_path('../info_routes', __FILE__) if Rails.env.development? - end - def log_level @log_level ||= Rails.env.production? ? :info : :debug end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 855467227b..a45b61c99c 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -4,7 +4,7 @@ module Rails include Initializable initializer :add_generator_templates do - config.generators.templates.unshift(*paths.lib.templates.to_a) + config.generators.templates.unshift(*paths["lib/templates"].existent) end initializer :ensure_autoload_once_paths_as_subset do @@ -21,13 +21,15 @@ module Rails initializer :add_to_prepare_blocks do config.to_prepare_blocks.each do |block| - ActionDispatch::Callbacks.to_prepare(&block) + ActionDispatch::Reloader.to_prepare(&block) end end initializer :add_builtin_route do |app| if Rails.env.development? - app.routes_reloader.paths << File.expand_path('../../info_routes.rb', __FILE__) + app.routes.append do + match '/rails/info/properties' => "rails/info#properties" + end end end @@ -35,6 +37,10 @@ module Rails build_middleware_stack end + 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) @@ -46,6 +52,13 @@ module Rails ActiveSupport.run_load_hooks(:after_initialize, self) end + # Force routes to be loaded just at the end and add it to to_prepare callbacks + initializer :set_routes_reloader do |app| + reloader = lambda { app.routes_reloader.execute_if_updated } + reloader.call + ActionDispatch::Reloader.to_prepare(&reloader) + 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/railties.rb b/railties/lib/rails/application/railties.rb index b3e6693f89..4fc5e92837 100644 --- a/railties/lib/rails/application/railties.rb +++ b/railties/lib/rails/application/railties.rb @@ -1,31 +1,13 @@ -module Rails - class Application - class Railties - # TODO Write tests for this behavior extracted from Application - def initialize(config) - @config = config - end +require 'rails/engine/railties' +module Rails + class Application < Engine + class Railties < Rails::Engine::Railties def all(&block) - @all ||= railties + engines + plugins + @all ||= railties + engines + super @all.each(&block) if block @all end - - def railties - @railties ||= ::Rails::Railtie.subclasses.map(&:new) - end - - def engines - @engines ||= ::Rails::Engine.subclasses.map(&:new) - end - - def plugins - @plugins ||= begin - plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym } - Plugin.all(plugin_names, @config.paths.vendor.plugins) - end - end end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb new file mode 100644 index 0000000000..1d1f5e1b06 --- /dev/null +++ b/railties/lib/rails/application/routes_reloader.rb @@ -0,0 +1,45 @@ +module Rails + class Application + class RoutesReloader < ::ActiveSupport::FileUpdateChecker + attr_reader :route_sets + + def initialize + super([]) { reload! } + @route_sets = [] + end + + def reload! + clear! + load_paths + finalize! + ensure + revert + end + + protected + + def clear! + route_sets.each do |routes| + routes.disable_clear_and_finalize = true + routes.clear! + end + end + + def load_paths + paths.each { |path| load(path) } + end + + def finalize! + route_sets.each do |routes| + ActiveSupport.on_load(:action_controller) { routes.finalize! } + end + end + + def revert + route_sets.each do |routes| + routes.disable_clear_and_finalize = false + end + end + end + end +end |