Browse files

Remove unnecessary Railties structure now that plugins are gone

  • Loading branch information...
1 parent e9e6f63 commit 0470ddcf0301e537d5151d62177eadba5eae182d @josevalim josevalim committed Jun 29, 2012
View
127 railties/lib/rails/application.rb
@@ -53,7 +53,6 @@ class Application < Engine
autoload :Bootstrap, 'rails/application/bootstrap'
autoload :Configuration, 'rails/application/configuration'
autoload :Finisher, 'rails/application/finisher'
- autoload :Railties, 'rails/application/railties'
autoload :RoutesReloader, 'rails/application/routes_reloader'
class << self
@@ -83,6 +82,61 @@ def initialize
@queue = nil
end
+ def initialized?
+ @initialized
+ end
+
+ # Implements call according to the Rack API. It simples
+ # dispatch the request to the underlying middleware stack.
+ def call(env)
+ env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
+ super(env)
+ end
+
+ # Reload application routes regardless if they changed or not.
+ def reload_routes!
+ routes_reloader.reload!
+ end
+
+ # Load the application and its railties tasks and invoke the registered hooks.
+ # Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
+ def load_tasks(app=self)
+ initialize_tasks
+ super
+ self
+ end
+
+ # Load the application console and invoke the registered hooks.
+ # Check <tt>Rails::Railtie.console</tt> for more info.
+ def load_console(app=self)
+ initialize_console
+ super
+ self
+ end
+
+ # Load the application runner and invoke the registered hooks.
+ # Check <tt>Rails::Railtie.runner</tt> for more info.
+ def load_runner(app=self)
+ initialize_runner
+ super
+ self
+ end
+
+ # Stores some of the Rails initial environment parameters which
+ # will be used by middlewares and engines to configure themselves.
+ def env_config
+ @env_config ||= super.merge({
+ "action_dispatch.parameter_filter" => config.filter_parameters,
+ "action_dispatch.secret_token" => config.secret_token,
+ "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
+ "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
+ "action_dispatch.logger" => Rails.logger,
+ "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
+ })
+ end
+
+ ## Rails internal API
+
# This method is called just after an application inherits from Rails::Application,
# allowing the developer to load classes in lib and use them during application
# configuration.
@@ -106,18 +160,14 @@ def require_environment! #:nodoc:
require environment if environment
end
- # Reload application routes regardless if they changed or not.
- def reload_routes!
- routes_reloader.reload!
- end
-
def routes_reloader #:nodoc:
@routes_reloader ||= RoutesReloader.new
end
- # Returns an array of file paths appended with a hash of directories-extensions
- # suitable for ActiveSupport::FileUpdateChecker API.
- def watchable_args
+ # Returns an array of file paths appended with a hash of
+ # directories-extensions suitable for ActiveSupport::FileUpdateChecker
+ # API.
+ def watchable_args #:nodoc:
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
ActiveSupport::Dependencies.autoload_paths.each do |path|
@@ -138,47 +188,6 @@ def initialize!(group=:default) #:nodoc:
self
end
- def initialized?
- @initialized
- end
-
- # Load the application and its railties tasks and invoke the registered hooks.
- # Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
- def load_tasks(app=self)
- initialize_tasks
- super
- self
- end
-
- # Load the application console and invoke the registered hooks.
- # Check <tt>Rails::Railtie.console</tt> for more info.
- def load_console(app=self)
- initialize_console
- super
- self
- end
-
- # Load the application runner and invoke the registered hooks.
- # Check <tt>Rails::Railtie.runner</tt> for more info.
- def load_runner(app=self)
- initialize_runner
- super
- self
- end
-
- # Stores some of the Rails initial environment parameters which
- # will be used by middlewares and engines to configure themselves.
- def env_config
- @env_config ||= super.merge({
- "action_dispatch.parameter_filter" => config.filter_parameters,
- "action_dispatch.secret_token" => config.secret_token,
- "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
- "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
- "action_dispatch.logger" => Rails.logger,
- "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
- })
- end
-
# Returns the ordered railties for this application considering railties_order.
def ordered_railties #:nodoc:
@ordered_railties ||= begin
@@ -192,7 +201,7 @@ def ordered_railties #:nodoc:
end
end
- all = (railties.all - order)
+ all = (railties - order)
all.push(self) unless (all + order).include?(self)
order.push(:all) unless order.include?(:all)
@@ -216,32 +225,32 @@ def queue #:nodoc:
@queue ||= build_queue
end
- def build_queue # :nodoc:
+ def build_queue #:nodoc:
config.queue.new
end
- def to_app
+ def to_app #:nodoc:
self
end
def helpers_paths #:nodoc:
config.helpers_paths
end
- def call(env)
- env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
- super(env)
+ def railties #:nodoc:
+ @railties ||= Rails::Railtie.subclasses.map(&:instance) +
+ Rails::Engine.subclasses.map(&:instance)
end
protected
alias :build_middleware_stack :app
- def reload_dependencies?
+ def reload_dependencies? #:nodoc:
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
end
- def default_middleware_stack
+ def default_middleware_stack #:nodoc:
ActionDispatch::MiddlewareStack.new.tap do |middleware|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
require "action_dispatch/http/rack_cache"
@@ -315,7 +324,7 @@ def initialize_console #:nodoc:
def initialize_runner #:nodoc:
end
- def build_original_fullpath(env)
+ def build_original_fullpath(env) #:nodoc:
path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"]
script_name = env["SCRIPT_NAME"]
View
13 railties/lib/rails/application/railties.rb
@@ -1,13 +0,0 @@
-require 'rails/engine/railties'
-
-module Rails
- class Application < Engine
- class Railties < Rails::Engine::Railties
- def all(&block)
- @all ||= railties + engines
- @all.each(&block) if block
- @all
- end
- end
- end
-end
View
24 railties/lib/rails/engine.rb
@@ -2,7 +2,6 @@
require 'active_support/core_ext/module/delegation'
require 'pathname'
require 'rbconfig'
-require 'rails/engine/railties'
module Rails
# <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of
@@ -338,7 +337,6 @@ module Rails
# config.railties_order = [Blog::Engine, :main_app, :all]
class Engine < Railtie
autoload :Configuration, "rails/engine/configuration"
- autoload :Railties, "rails/engine/railties"
def initialize
@_all_autoload_paths = nil
@@ -354,7 +352,7 @@ def initialize
def load_generators(app=self)
initialize_generators
- railties.all { |r| r.load_generators(app) }
+ railties.each { |r| r.load_generators(app) }
Rails::Generators.configure!(app.config.generators)
super
self
@@ -417,33 +415,35 @@ def isolate_namespace(mod)
# Finds engine with given path
def find(path)
expanded_path = File.expand_path path
- Rails::Engine::Railties.engines.find { |engine|
- File.expand_path(engine.root) == expanded_path
- }
+ Rails::Engine.subclasses.each do |klass|
+ engine = klass.instance
+ return engine if File.expand_path(engine.root) == expanded_path
+ end
+ nil
end
end
delegate :middleware, :root, :paths, :to => :config
delegate :engine_name, :isolated?, :to => "self.class"
def load_tasks(app=self)
- railties.all { |r| r.load_tasks(app) }
+ railties.each { |r| r.load_tasks(app) }
super
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end
def load_console(app=self)
- railties.all { |r| r.load_console(app) }
+ railties.each { |r| r.load_console(app) }
super
end
def load_runner(app=self)
- railties.all { |r| r.load_runner(app) }
+ railties.each { |r| r.load_runner(app) }
super
end
def eager_load!
- railties.all(&:eager_load!)
+ railties.each(&:eager_load!)
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
@@ -454,7 +454,7 @@ def eager_load!
end
def railties
- @railties ||= self.class::Railties.new(config)
+ @railties ||= []
end
def helpers
@@ -507,7 +507,7 @@ def routes
end
def ordered_railties
- railties.all + [self]
+ railties + [self]
end
def initializers
View
26 railties/lib/rails/engine/railties.rb
@@ -1,26 +0,0 @@
-module Rails
- class Engine < Railtie
- class Railties
- # TODO Write tests for this behavior extracted from Application
- def initialize(config)
- @config = config
- end
-
- def all(&block)
- @all ||= []
- @all.each(&block) if block
- @all
- end
-
- def self.railties
- @railties ||= ::Rails::Railtie.subclasses.map(&:instance)
- end
-
- def self.engines
- @engines ||= ::Rails::Engine.subclasses.map(&:instance)
- end
-
- delegate :railties, :engines, :to => "self.class"
- end
- end
-end
View
16 railties/test/isolation/abstract_unit.rb
@@ -273,24 +273,18 @@ class ActiveSupport::TestCase
# Create a scope and build a fixture rails app
Module.new do
extend TestHelpers::Paths
+
# Build a rails app
- if File.exist?(app_template_path)
- FileUtils.rm_rf(app_template_path)
- end
+ FileUtils.rm_rf(app_template_path)
FileUtils.mkdir(app_template_path)
environment = File.expand_path('../../../../load_paths', __FILE__)
- if File.exist?("#{environment}.rb")
- require_environment = "-r #{environment}"
- end
+ require_environment = "-r #{environment}"
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{app_template_path}`
+
File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
- if require_environment
- f.puts "Dir.chdir('#{File.dirname(environment)}') do"
- f.puts " require '#{environment}'"
- f.puts "end"
- end
+ f.puts "require '#{environment}'"
f.puts "require 'rails/all'"
end
end unless defined?(RAILS_ISOLATED_ENGINE)

2 comments on commit 0470ddc

@pixeltrix
Ruby on Rails member

This commit breaks Thinking Sphinx which uses the Rails::Engine::Railties#engines method to get a list of engines to search for models. It's obviously a trivial patch to search the new array for railtie.is_a?(Rails::Engine) but I'm not sure whether this is an api that other gems may be using so we might want to wrap the array with something to provide backwards compatibility.

@josevalim
Ruby on Rails member

Yes, we should probably wrap it for backwards compatibility and slap a deprecation warning. Good point @pixeltrix .

Please sign in to comment.