aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application.rb49
-rw-r--r--railties/lib/rails/application/bootstrap.rb2
-rw-r--r--railties/lib/rails/application/configuration.rb33
-rw-r--r--railties/lib/rails/application/finisher.rb2
-rw-r--r--railties/lib/rails/application/metal_loader.rb50
-rw-r--r--railties/lib/rails/engine.rb7
-rw-r--r--railties/lib/rails/engine/configuration.rb1
-rw-r--r--railties/lib/rails/generators/base.rb2
-rw-r--r--railties/lib/rails/generators/rails/metal/USAGE8
-rw-r--r--railties/lib/rails/generators/rails/metal/metal_generator.rb11
-rw-r--r--railties/lib/rails/generators/rails/metal/templates/metal.rb12
-rw-r--r--railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
-rw-r--r--railties/lib/rails/tasks/framework.rake2
-rw-r--r--railties/lib/rails/tasks/middleware.rake2
15 files changed, 52 insertions, 133 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index a3b3a56bc8..85ae8cbbb1 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -27,7 +27,7 @@ module Rails
# Besides providing the same configuration as Rails::Engine and Rails::Railtie,
# the application object has several specific configurations, for example
# "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters",
- # "logger", "metals", "reload_engines", "reload_plugins" and so forth.
+ # "logger", "reload_engines", "reload_plugins" and so forth.
#
# Check Rails::Application::Configuration to see them all.
#
@@ -36,17 +36,15 @@ module Rails
# The application object is also responsible for holding the routes and reloading routes
# whenever the files change in development.
#
- # == Middlewares and metals
+ # == Middlewares
#
- # The Application is also responsible for building the middleware stack and setting up
- # both application and engines metals.
+ # The Application is also responsible for building the middleware stack.
#
class Application < Engine
autoload :Bootstrap, 'rails/application/bootstrap'
autoload :Configurable, 'rails/application/configurable'
autoload :Configuration, 'rails/application/configuration'
autoload :Finisher, 'rails/application/finisher'
- autoload :MetalLoader, 'rails/application/metal_loader'
autoload :Railties, 'rails/application/railties'
autoload :RoutesReloader, 'rails/application/routes_reloader'
@@ -69,6 +67,7 @@ module Rails
raise "You cannot have more than one Rails::Application" if Rails.application
super
Rails.application = base.instance
+ Rails.application.add_lib_to_load_paths!
ActiveSupport.run_load_hooks(:before_configuration, base.instance)
end
@@ -83,13 +82,23 @@ module Rails
end
end
- delegate :middleware, :metal_loader, :to => :config
+ delegate :middleware, :to => :config
+
+ def add_lib_to_load_paths!
+ path = config.root.join('lib').to_s
+ $LOAD_PATH.unshift(path) if File.exists?(path)
+ end
def require_environment!
environment = paths.config.environment.to_a.first
require environment if environment
end
+ def eager_load!
+ railties.all(&:eager_load!)
+ super
+ end
+
def routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
@@ -126,7 +135,10 @@ module Rails
end
def app
- @app ||= config.middleware.build(routes)
+ @app ||= begin
+ config.middleware = config.middleware.merge_into(default_middleware_stack)
+ config.middleware.build(routes)
+ end
end
def call(env)
@@ -150,6 +162,29 @@ module Rails
protected
+ def default_middleware_stack
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets
+ middleware.use ::Rack::Lock if !config.allow_concurrency
+ middleware.use ::Rack::Runtime
+ middleware.use ::Rails::Rack::Logger
+ middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions
+ middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
+ middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
+ middleware.use ::ActionDispatch::Callbacks, !config.cache_classes
+ middleware.use ::ActionDispatch::Cookies
+
+ if config.session_store
+ middleware.use config.session_store, config.session_options
+ middleware.use ::ActionDispatch::Flash
+ end
+
+ middleware.use ::ActionDispatch::ParamsParser
+ middleware.use ::Rack::MethodOverride
+ middleware.use ::ActionDispatch::Head
+ end
+ end
+
def initialize_tasks
require "rails/tasks"
task :environment do
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index e62eed8a87..0a435f0f36 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -47,7 +47,7 @@ module Rails
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) }
if RAILS_CACHE.respond_to?(:middleware)
- config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware)
+ config.middleware.insert_before("Rack::Runtime", RAILS_CACHE.middleware)
end
end
end
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 1b8af370f7..25e54e9dce 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -9,7 +9,7 @@ module Rails
attr_accessor :allow_concurrency, :cache_classes, :cache_store,
:encoding, :consider_all_requests_local, :dependency_loading,
- :filter_parameters, :log_level, :logger, :metals,
+ :filter_parameters, :log_level, :logger, :middleware,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
:secret_token, :serve_static_assets, :session_options,
:time_zone, :whiny_nils
@@ -25,6 +25,7 @@ module Rails
@session_store = :cookie_store
@session_options = {}
@time_zone = "UTC"
+ @middleware = app_middleware
end
def encoding=(value)
@@ -41,14 +42,6 @@ module Rails
end
end
- def middleware
- @middleware ||= app_middleware.merge_into(default_middleware_stack)
- end
-
- def metal_loader
- @metal_loader ||= Rails::Application::MetalLoader.new
- end
-
def paths
@paths ||= begin
paths = super
@@ -138,28 +131,6 @@ module Rails
@session_options = args.shift || {}
end
end
-
- protected
-
- def default_middleware_stack
- ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use('::ActionDispatch::Static', lambda { paths.public.to_a.first }, :if => lambda { serve_static_assets })
- middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
- middleware.use('::Rack::Runtime')
- middleware.use('::Rails::Rack::Logger')
- middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local }, :if => lambda { action_dispatch.show_exceptions })
- middleware.use('::ActionDispatch::RemoteIp', lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies })
- middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header })
- middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes })
- middleware.use('::ActionDispatch::Cookies')
- middleware.use(lambda { session_store }, lambda { session_options })
- middleware.use('::ActionDispatch::Flash', :if => lambda { session_store })
- middleware.use('::ActionDispatch::ParamsParser')
- middleware.use('::Rack::MethodOverride')
- middleware.use('::ActionDispatch::Head')
- middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? })
- end
- end
end
end
end
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index fbab4d5515..d7ff489336 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -38,7 +38,7 @@ module Rails
initializer :eager_load! do
if config.cache_classes && !$rails_rake_task
ActiveSupport.run_load_hooks(:before_eager_load, self)
- railties.all(&:eager_load!)
+ eager_load!
end
end
diff --git a/railties/lib/rails/application/metal_loader.rb b/railties/lib/rails/application/metal_loader.rb
deleted file mode 100644
index 2a43fa7892..0000000000
--- a/railties/lib/rails/application/metal_loader.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'action_dispatch'
-
-module Rails
- class Application
- class MetalLoader
- attr_reader :paths, :metals
-
- def initialize
- @paths, @metals = [], []
- end
-
- def build_middleware(list=nil)
- load_metals!(list)
- self
- end
-
- def new(app)
- ActionDispatch::Cascade.new(@metals, app)
- end
-
- def name
- ActionDispatch::Cascade.name
- end
- alias :to_s :name
-
- protected
-
- def load_metals!(list)
- metals = []
- list = Array(list || :all).map(&:to_sym)
-
- paths.each do |path|
- matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
- Dir.glob("#{path}/**/*.rb").sort.each do |metal_path|
- metal = metal_path.sub(matcher, '\1').to_sym
- next unless list.include?(metal) || list.include?(:all)
- require_dependency metal.to_s
- metals << metal
- end
- end
-
- metals = metals.sort_by do |m|
- [list.index(m) || list.index(:all), m.to_s]
- end
-
- @metals = metals.map { |m| m.to_s.camelize.constantize }
- end
- end
- end
-end
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index b44755820c..cdb00a4eff 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -25,7 +25,7 @@ module Rails
# end
#
# Then ensure that this file is loaded at the top of your config/application.rb (or in
- # your Gemfile) and it will automatically load models, controllers, helpers and metals
+ # your Gemfile) and it will automatically load models, controllers and helpers
# inside app, load routes at "config/routes.rb", load locales at "config/locales/*",
# load tasks at "lib/tasks/*".
#
@@ -73,7 +73,6 @@ module Rails
# paths.app.controllers = "app/controllers"
# paths.app.helpers = "app/helpers"
# paths.app.models = "app/models"
- # paths.app.metals = "app/metal"
# paths.app.views = "app/views"
# paths.lib = "lib"
# paths.lib.tasks = "lib/tasks"
@@ -202,10 +201,6 @@ module Rails
end
end
- initializer :add_metals do |app|
- app.metal_loader.paths.unshift(*paths.app.metals.to_a)
- end
-
initializer :load_config_initializers do
paths.config.initializers.to_a.sort.each do |initializer|
load(initializer)
diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb
index c5411a0331..446fe0bda9 100644
--- a/railties/lib/rails/engine/configuration.rb
+++ b/railties/lib/rails/engine/configuration.rb
@@ -19,7 +19,6 @@ module Rails
paths.app.helpers "app/helpers", :eager_load => true
paths.app.models "app/models", :eager_load => true
paths.app.mailers "app/mailers", :eager_load => true
- paths.app.metals "app/metal", :eager_load => true
paths.app.views "app/views"
paths.lib "lib", :load_path => true
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 766644bbc2..bd2260fc29 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -288,7 +288,7 @@ module Rails
end
# Removes the namespaces and get the generator name. For example,
- # Rails::Generators::MetalGenerator will return "metal" as generator name.
+ # Rails::Generators::ModelGenerator will return "model" as generator name.
#
def self.generator_name
@generator_name ||= begin
diff --git a/railties/lib/rails/generators/rails/metal/USAGE b/railties/lib/rails/generators/rails/metal/USAGE
deleted file mode 100644
index c88325a444..0000000000
--- a/railties/lib/rails/generators/rails/metal/USAGE
+++ /dev/null
@@ -1,8 +0,0 @@
-Description:
- Cast some metal!
-
-Examples:
- `rails generate metal poller`
-
- This will create:
- Metal: app/metal/poller.rb
diff --git a/railties/lib/rails/generators/rails/metal/metal_generator.rb b/railties/lib/rails/generators/rails/metal/metal_generator.rb
deleted file mode 100644
index fe4f945cad..0000000000
--- a/railties/lib/rails/generators/rails/metal/metal_generator.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Rails
- module Generators
- class MetalGenerator < NamedBase
- check_class_collision
-
- def create_metal_file
- template "metal.rb", "app/metal/#{file_name}.rb"
- end
- end
- end
-end
diff --git a/railties/lib/rails/generators/rails/metal/templates/metal.rb b/railties/lib/rails/generators/rails/metal/templates/metal.rb
deleted file mode 100644
index 8cc3f1f258..0000000000
--- a/railties/lib/rails/generators/rails/metal/templates/metal.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# Allow the metal piece to run in isolation
-require File.expand_path('../../../config/environment', __FILE__) unless defined?(Rails)
-
-class <%= class_name %>
- def self.call(env)
- if env["PATH_INFO"] =~ /^\/<%= file_name %>/
- [200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
- else
- [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
- end
- end
-end
diff --git a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
index 2c57158b1c..de0823749c 100644
--- a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
+++ b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class <%= class_name %>Test < ActionController::IntegrationTest
+class <%= class_name %>Test < ActionDispatch::IntegrationTest
fixtures :all
# Replace this with your real tests.
diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
index 362e3dc09f..e827aa918f 100644
--- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
+++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
require 'rails/performance_test_help'
-class <%= class_name %>Test < ActionController::PerformanceTest
+class <%= class_name %>Test < ActionDispatch::PerformanceTest
# Replace this with your real tests.
def test_homepage
get '/'
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 063a393bfc..ac510eee2e 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -37,7 +37,7 @@ namespace :rails do
project_templates = "#{Rails.root}/lib/templates"
default_templates = { "erb" => %w{controller mailer scaffold},
- "rails" => %w{controller helper metal scaffold_controller stylesheets} }
+ "rails" => %w{controller helper scaffold_controller stylesheets} }
default_templates.each do |type, names|
local_template_type_dir = File.join(project_templates, type)
diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake
index 251da67c96..e670989345 100644
--- a/railties/lib/rails/tasks/middleware.rake
+++ b/railties/lib/rails/tasks/middleware.rake
@@ -1,6 +1,6 @@
desc 'Prints out your Rack middleware stack'
task :middleware => :environment do
- Rails.configuration.middleware.active.each do |middleware|
+ Rails.configuration.middleware.each do |middleware|
puts "use #{middleware.inspect}"
end
puts "run #{Rails::Application.instance.class.name}.routes"