mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove unnecessary Railties structure now that plugins are gone
This commit is contained in:
parent
e9e6f63d9c
commit
0470ddcf03
5 changed files with 86 additions and 122 deletions
|
@ -53,7 +53,6 @@ module Rails
|
||||||
autoload :Bootstrap, 'rails/application/bootstrap'
|
autoload :Bootstrap, 'rails/application/bootstrap'
|
||||||
autoload :Configuration, 'rails/application/configuration'
|
autoload :Configuration, 'rails/application/configuration'
|
||||||
autoload :Finisher, 'rails/application/finisher'
|
autoload :Finisher, 'rails/application/finisher'
|
||||||
autoload :Railties, 'rails/application/railties'
|
|
||||||
autoload :RoutesReloader, 'rails/application/routes_reloader'
|
autoload :RoutesReloader, 'rails/application/routes_reloader'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -83,27 +82,15 @@ module Rails
|
||||||
@queue = nil
|
@queue = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method is called just after an application inherits from Rails::Application,
|
def initialized?
|
||||||
# allowing the developer to load classes in lib and use them during application
|
@initialized
|
||||||
# configuration.
|
|
||||||
#
|
|
||||||
# class MyApplication < Rails::Application
|
|
||||||
# require "my_backend" # in lib/my_backend
|
|
||||||
# config.i18n.backend = MyBackend
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# Notice this method takes into consideration the default root path. So if you
|
|
||||||
# are changing config.root inside your application definition or having a custom
|
|
||||||
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
|
|
||||||
# you need to load files in lib/ during the application configuration as well.
|
|
||||||
def add_lib_to_load_path! #:nodoc:
|
|
||||||
path = File.join config.root, 'lib'
|
|
||||||
$LOAD_PATH.unshift(path) if File.exists?(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_environment! #:nodoc:
|
# Implements call according to the Rack API. It simples
|
||||||
environment = paths["config/environment"].existent.first
|
# dispatch the request to the underlying middleware stack.
|
||||||
require environment if environment
|
def call(env)
|
||||||
|
env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
|
||||||
|
super(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reload application routes regardless if they changed or not.
|
# Reload application routes regardless if they changed or not.
|
||||||
|
@ -111,37 +98,6 @@ module Rails
|
||||||
routes_reloader.reload!
|
routes_reloader.reload!
|
||||||
end
|
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
|
|
||||||
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
|
|
||||||
|
|
||||||
ActiveSupport::Dependencies.autoload_paths.each do |path|
|
|
||||||
dirs[path.to_s] = [:rb]
|
|
||||||
end
|
|
||||||
|
|
||||||
[files, dirs]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Initialize the application passing the given group. By default, the
|
|
||||||
# group is :default but sprockets precompilation passes group equals
|
|
||||||
# to assets if initialize_on_precompile is false to avoid booting the
|
|
||||||
# whole app.
|
|
||||||
def initialize!(group=:default) #:nodoc:
|
|
||||||
raise "Application has been already initialized." if @initialized
|
|
||||||
run_initializers(group, self)
|
|
||||||
@initialized = true
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialized?
|
|
||||||
@initialized
|
|
||||||
end
|
|
||||||
|
|
||||||
# Load the application and its railties tasks and invoke the registered hooks.
|
# Load the application and its railties tasks and invoke the registered hooks.
|
||||||
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
|
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
|
||||||
def load_tasks(app=self)
|
def load_tasks(app=self)
|
||||||
|
@ -179,6 +135,59 @@ module Rails
|
||||||
})
|
})
|
||||||
end
|
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.
|
||||||
|
#
|
||||||
|
# class MyApplication < Rails::Application
|
||||||
|
# require "my_backend" # in lib/my_backend
|
||||||
|
# config.i18n.backend = MyBackend
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Notice this method takes into consideration the default root path. So if you
|
||||||
|
# are changing config.root inside your application definition or having a custom
|
||||||
|
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
|
||||||
|
# you need to load files in lib/ during the application configuration as well.
|
||||||
|
def add_lib_to_load_path! #:nodoc:
|
||||||
|
path = File.join config.root, 'lib'
|
||||||
|
$LOAD_PATH.unshift(path) if File.exists?(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_environment! #:nodoc:
|
||||||
|
environment = paths["config/environment"].existent.first
|
||||||
|
require environment if environment
|
||||||
|
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 #:nodoc:
|
||||||
|
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
|
||||||
|
|
||||||
|
ActiveSupport::Dependencies.autoload_paths.each do |path|
|
||||||
|
dirs[path.to_s] = [:rb]
|
||||||
|
end
|
||||||
|
|
||||||
|
[files, dirs]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Initialize the application passing the given group. By default, the
|
||||||
|
# group is :default but sprockets precompilation passes group equals
|
||||||
|
# to assets if initialize_on_precompile is false to avoid booting the
|
||||||
|
# whole app.
|
||||||
|
def initialize!(group=:default) #:nodoc:
|
||||||
|
raise "Application has been already initialized." if @initialized
|
||||||
|
run_initializers(group, self)
|
||||||
|
@initialized = true
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the ordered railties for this application considering railties_order.
|
# Returns the ordered railties for this application considering railties_order.
|
||||||
def ordered_railties #:nodoc:
|
def ordered_railties #:nodoc:
|
||||||
@ordered_railties ||= begin
|
@ordered_railties ||= begin
|
||||||
|
@ -192,7 +201,7 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
all = (railties.all - order)
|
all = (railties - order)
|
||||||
all.push(self) unless (all + order).include?(self)
|
all.push(self) unless (all + order).include?(self)
|
||||||
order.push(:all) unless order.include?(:all)
|
order.push(:all) unless order.include?(:all)
|
||||||
|
|
||||||
|
@ -216,11 +225,11 @@ module Rails
|
||||||
@queue ||= build_queue
|
@queue ||= build_queue
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_queue # :nodoc:
|
def build_queue #:nodoc:
|
||||||
config.queue.new
|
config.queue.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_app
|
def to_app #:nodoc:
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -228,20 +237,20 @@ module Rails
|
||||||
config.helpers_paths
|
config.helpers_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def railties #:nodoc:
|
||||||
env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
|
@railties ||= Rails::Railtie.subclasses.map(&:instance) +
|
||||||
super(env)
|
Rails::Engine.subclasses.map(&:instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
alias :build_middleware_stack :app
|
alias :build_middleware_stack :app
|
||||||
|
|
||||||
def reload_dependencies?
|
def reload_dependencies? #:nodoc:
|
||||||
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
|
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_middleware_stack
|
def default_middleware_stack #:nodoc:
|
||||||
ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
||||||
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
|
||||||
require "action_dispatch/http/rack_cache"
|
require "action_dispatch/http/rack_cache"
|
||||||
|
@ -315,7 +324,7 @@ module Rails
|
||||||
def initialize_runner #:nodoc:
|
def initialize_runner #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_original_fullpath(env)
|
def build_original_fullpath(env) #:nodoc:
|
||||||
path_info = env["PATH_INFO"]
|
path_info = env["PATH_INFO"]
|
||||||
query_string = env["QUERY_STRING"]
|
query_string = env["QUERY_STRING"]
|
||||||
script_name = env["SCRIPT_NAME"]
|
script_name = env["SCRIPT_NAME"]
|
||||||
|
|
|
@ -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
|
|
|
@ -2,7 +2,6 @@ require 'rails/railtie'
|
||||||
require 'active_support/core_ext/module/delegation'
|
require 'active_support/core_ext/module/delegation'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require 'rails/engine/railties'
|
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
# <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of
|
# <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]
|
# config.railties_order = [Blog::Engine, :main_app, :all]
|
||||||
class Engine < Railtie
|
class Engine < Railtie
|
||||||
autoload :Configuration, "rails/engine/configuration"
|
autoload :Configuration, "rails/engine/configuration"
|
||||||
autoload :Railties, "rails/engine/railties"
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@_all_autoload_paths = nil
|
@_all_autoload_paths = nil
|
||||||
|
@ -354,7 +352,7 @@ module Rails
|
||||||
|
|
||||||
def load_generators(app=self)
|
def load_generators(app=self)
|
||||||
initialize_generators
|
initialize_generators
|
||||||
railties.all { |r| r.load_generators(app) }
|
railties.each { |r| r.load_generators(app) }
|
||||||
Rails::Generators.configure!(app.config.generators)
|
Rails::Generators.configure!(app.config.generators)
|
||||||
super
|
super
|
||||||
self
|
self
|
||||||
|
@ -417,9 +415,11 @@ module Rails
|
||||||
# Finds engine with given path
|
# Finds engine with given path
|
||||||
def find(path)
|
def find(path)
|
||||||
expanded_path = File.expand_path path
|
expanded_path = File.expand_path path
|
||||||
Rails::Engine::Railties.engines.find { |engine|
|
Rails::Engine.subclasses.each do |klass|
|
||||||
File.expand_path(engine.root) == expanded_path
|
engine = klass.instance
|
||||||
}
|
return engine if File.expand_path(engine.root) == expanded_path
|
||||||
|
end
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -427,23 +427,23 @@ module Rails
|
||||||
delegate :engine_name, :isolated?, :to => "self.class"
|
delegate :engine_name, :isolated?, :to => "self.class"
|
||||||
|
|
||||||
def load_tasks(app=self)
|
def load_tasks(app=self)
|
||||||
railties.all { |r| r.load_tasks(app) }
|
railties.each { |r| r.load_tasks(app) }
|
||||||
super
|
super
|
||||||
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_console(app=self)
|
def load_console(app=self)
|
||||||
railties.all { |r| r.load_console(app) }
|
railties.each { |r| r.load_console(app) }
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_runner(app=self)
|
def load_runner(app=self)
|
||||||
railties.all { |r| r.load_runner(app) }
|
railties.each { |r| r.load_runner(app) }
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def eager_load!
|
def eager_load!
|
||||||
railties.all(&:eager_load!)
|
railties.each(&:eager_load!)
|
||||||
|
|
||||||
config.eager_load_paths.each do |load_path|
|
config.eager_load_paths.each do |load_path|
|
||||||
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
|
||||||
|
@ -454,7 +454,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def railties
|
def railties
|
||||||
@railties ||= self.class::Railties.new(config)
|
@railties ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def helpers
|
def helpers
|
||||||
|
@ -507,7 +507,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_railties
|
def ordered_railties
|
||||||
railties.all + [self]
|
railties + [self]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initializers
|
def initializers
|
||||||
|
|
|
@ -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
|
|
|
@ -273,24 +273,18 @@ end
|
||||||
# Create a scope and build a fixture rails app
|
# Create a scope and build a fixture rails app
|
||||||
Module.new do
|
Module.new do
|
||||||
extend TestHelpers::Paths
|
extend TestHelpers::Paths
|
||||||
|
|
||||||
# Build a rails app
|
# Build a rails app
|
||||||
if File.exist?(app_template_path)
|
FileUtils.rm_rf(app_template_path)
|
||||||
FileUtils.rm_rf(app_template_path)
|
|
||||||
end
|
|
||||||
FileUtils.mkdir(app_template_path)
|
FileUtils.mkdir(app_template_path)
|
||||||
|
|
||||||
environment = File.expand_path('../../../../load_paths', __FILE__)
|
environment = File.expand_path('../../../../load_paths', __FILE__)
|
||||||
if File.exist?("#{environment}.rb")
|
require_environment = "-r #{environment}"
|
||||||
require_environment = "-r #{environment}"
|
|
||||||
end
|
|
||||||
|
|
||||||
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{app_template_path}`
|
`#{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|
|
File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
|
||||||
if require_environment
|
f.puts "require '#{environment}'"
|
||||||
f.puts "Dir.chdir('#{File.dirname(environment)}') do"
|
|
||||||
f.puts " require '#{environment}'"
|
|
||||||
f.puts "end"
|
|
||||||
end
|
|
||||||
f.puts "require 'rails/all'"
|
f.puts "require 'rails/all'"
|
||||||
end
|
end
|
||||||
end unless defined?(RAILS_ISOLATED_ENGINE)
|
end unless defined?(RAILS_ISOLATED_ENGINE)
|
||||||
|
|
Loading…
Reference in a new issue