Skip to content

Commit 45e6028

Browse files
committed
Removing Metal from Rails 3.
If you have existing Metals, you have a few options: * if your metal behaves like a middleware, add it to the middleware stack via config.middleware.use. You can use methods on the middleware stack to control exactly where it should go * if it behaves like a Rack endpoint, you can link to it in the router. This will result in more optimal routing time, and allows you to remove code in your endpoint that matches specific URLs in favor of the more powerful handling in the router itself. For the future, you can use ActionController::Metal to get a very fast controller with the ability to opt-in to specific controller features without paying the penalty of the full controller stack. Since Rails 3 is closer to Rack, the Metal abstraction is no longer needed.
1 parent 564ab47 commit 45e6028

File tree

20 files changed

+9
-319
lines changed

20 files changed

+9
-319
lines changed

actionpack/lib/action_dispatch.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ module ActionDispatch
4343

4444
autoload_under 'middleware' do
4545
autoload :Callbacks
46-
autoload :Cascade
4746
autoload :Cookies
4847
autoload :Flash
4948
autoload :Head

actionpack/lib/action_dispatch/middleware/cascade.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

railties/guides/source/configuring.textile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ h4. Rails General Configuration
6363

6464
* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging.
6565

66-
* +config.metals+ accepts an array used as the metals to load. If this is set to nil, all metals will be loaded in alphabetical order. If this is set to [], no metals will be loaded. Otherwise metals will be loaded in the order specified
67-
6866
* +config.plugin_loader+ overrides the class that handles loading each plugin. Defaults to +Rails::Plugin::Loader+.
6967

7068
* +config.plugin_locators+ overrides the class that handle finding the desired plugins that you‘d like to load for your application. By default it is the +Rails::Plugin::FileSystemLocator+.

railties/guides/source/initialization.textile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ This file requires _rails/railtie.rb_ which defines +Rails::Railtie+.
668668
* add_routing_namespaces
669669
* add_locales
670670
* add_view_paths
671-
* add_metals
672671
* add_generator_templates
673672
* load_application_initializers
674673
* load_application_classes
@@ -726,7 +725,6 @@ This file is used to set up the +Rails::Paths+ module which is used to set up he
726725
paths.app.helpers "app/helpers", :eager_load => true
727726
paths.app.models "app/models", :eager_load => true
728727
paths.app.mailers "app/mailers", :eager_load => true
729-
paths.app.metals "app/metal", :eager_load => true
730728
paths.app.views "app/views", :eager_load => true
731729
paths.lib "lib", :load_path => true
732730
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"
@@ -3154,7 +3152,6 @@ This method is defined like this:
31543152
middleware.use('ActionDispatch::Cookies')
31553153
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
31563154
middleware.use('ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store })
3157-
middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) })
31583155
middleware.use('ActionDispatch::ParamsParser')
31593156
middleware.use('::Rack::MethodOverride')
31603157
middleware.use('::ActionDispatch::Head')
@@ -3288,7 +3285,7 @@ Finally, a +Rails::Application::Configuration+ object will be returned. On this
32883285
<ruby>
32893286
attr_accessor :after_initialize_blocks, :cache_classes, :colorize_logging,
32903287
:consider_all_requests_local, :dependency_loading,
3291-
:load_once_paths, :logger, :metals, :plugins,
3288+
:load_once_paths, :logger, :plugins,
32923289
:preload_frameworks, :reload_plugins, :serve_static_assets,
32933290
:time_zone, :whiny_nils
32943291

@@ -3574,7 +3571,6 @@ The +super+ method it references comes from +Rails::Engine::Configuration+ which
35743571
paths.app.controllers "app/controllers", :eager_load => true
35753572
paths.app.helpers "app/helpers", :eager_load => true
35763573
paths.app.models "app/models", :eager_load => true
3577-
paths.app.metals "app/metal"
35783574
paths.app.views "app/views"
35793575
paths.lib "lib", :load_path => true
35803576
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"

railties/guides/source/rails_on_rack.textile

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -222,57 +222,6 @@ use MyOwnStackFromStratch
222222
run ActionController::Dispatcher.new
223223
</ruby>
224224

225-
h3. Rails Metal Applications
226-
227-
Rails Metal applications are minimal Rack applications specially designed for integrating with a typical Rails application. As Rails Metal Applications skip all of the Action Controller stack, serving a request has no overhead from the Rails framework itself. This is especially useful for infrequent cases where the performance of the full stack Rails framework is an issue.
228-
229-
Ryan Bates' "Railscast on Rails Metal":http://railscasts.com/episodes/150-rails-metal provides a nice walkthrough generating and using Rails Metal.
230-
231-
h4. Generating a Metal Application
232-
233-
Rails provides a generator called +metal+ for creating a new Metal application:
234-
235-
<shell>
236-
$ rails generate metal poller
237-
</shell>
238-
239-
This generates +poller.rb+ in the +app/metal+ directory:
240-
241-
<ruby>
242-
# Allow the metal piece to run in isolation
243-
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
244-
245-
class Poller
246-
def self.call(env)
247-
if env["PATH_INFO"] =~ /^\/poller/
248-
[200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
249-
else
250-
[404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
251-
end
252-
end
253-
end
254-
</ruby>
255-
256-
Metal applications within +app/metal+ folders in plugins will also be discovered and added to the list.
257-
258-
Metal applications are an optimization. You should make sure to "understand the related performance implications":http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal before using it.
259-
260-
WARNING: To continue the Metal chain execution, return an +X-Cascade+ HTTP header with a value of +pass+.
261-
262-
h4. Execution Order
263-
264-
All Metal Applications are executed in alphabetical order of their filenames, so +aaa.rb+ will come before +bbb.rb+ in the metal chain.
265-
266-
You can override the default ordering in your environment. Simply add a line like the following to +config/application.rb+
267-
268-
It is, however, possible to override the default ordering in your environment. Simply add a line like the following to +config/environment.rb+
269-
270-
<ruby>
271-
config.metals = ["Bbb", "Aaa"]
272-
</ruby>
273-
274-
Each string in the array should be the name of your metal class. If you do this then be warned that any metal applications not listed will not be loaded.
275-
276225
h3. Resources
277226

278227
h4. Learning Rack

railties/lib/rails/application.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Rails
2727
# Besides providing the same configuration as Rails::Engine and Rails::Railtie,
2828
# the application object has several specific configurations, for example
2929
# "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters",
30-
# "logger", "metals", "reload_engines", "reload_plugins" and so forth.
30+
# "logger", "reload_engines", "reload_plugins" and so forth.
3131
#
3232
# Check Rails::Application::Configuration to see them all.
3333
#
@@ -36,17 +36,15 @@ module Rails
3636
# The application object is also responsible for holding the routes and reloading routes
3737
# whenever the files change in development.
3838
#
39-
# == Middlewares and metals
39+
# == Middlewares
4040
#
41-
# The Application is also responsible for building the middleware stack and setting up
42-
# both application and engines metals.
41+
# The Application is also responsible for building the middleware stack.
4342
#
4443
class Application < Engine
4544
autoload :Bootstrap, 'rails/application/bootstrap'
4645
autoload :Configurable, 'rails/application/configurable'
4746
autoload :Configuration, 'rails/application/configuration'
4847
autoload :Finisher, 'rails/application/finisher'
49-
autoload :MetalLoader, 'rails/application/metal_loader'
5048
autoload :Railties, 'rails/application/railties'
5149
autoload :RoutesReloader, 'rails/application/routes_reloader'
5250

@@ -83,7 +81,7 @@ def method_missing(*args, &block)
8381
end
8482
end
8583

86-
delegate :middleware, :metal_loader, :to => :config
84+
delegate :middleware, :to => :config
8785

8886
def require_environment!
8987
environment = paths.config.environment.to_a.first

railties/lib/rails/application/configuration.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Configuration < ::Rails::Engine::Configuration
99

1010
attr_accessor :allow_concurrency, :cache_classes, :cache_store,
1111
:encoding, :consider_all_requests_local, :dependency_loading,
12-
:filter_parameters, :log_level, :logger, :metals,
12+
:filter_parameters, :log_level, :logger,
1313
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
1414
:secret_token, :serve_static_assets, :session_options,
1515
:time_zone, :whiny_nils
@@ -45,10 +45,6 @@ def middleware
4545
@middleware ||= app_middleware.merge_into(default_middleware_stack)
4646
end
4747

48-
def metal_loader
49-
@metal_loader ||= Rails::Application::MetalLoader.new
50-
end
51-
5248
def paths
5349
@paths ||= begin
5450
paths = super
@@ -157,7 +153,6 @@ def default_middleware_stack
157153
middleware.use('::ActionDispatch::ParamsParser')
158154
middleware.use('::Rack::MethodOverride')
159155
middleware.use('::ActionDispatch::Head')
160-
middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? })
161156
end
162157
end
163158
end

railties/lib/rails/application/metal_loader.rb

Lines changed: 0 additions & 50 deletions
This file was deleted.

railties/lib/rails/engine.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Rails
2525
# end
2626
#
2727
# Then ensure that this file is loaded at the top of your config/application.rb (or in
28-
# your Gemfile) and it will automatically load models, controllers, helpers and metals
28+
# your Gemfile) and it will automatically load models, controllers and helpers
2929
# inside app, load routes at "config/routes.rb", load locales at "config/locales/*",
3030
# load tasks at "lib/tasks/*".
3131
#
@@ -73,7 +73,6 @@ module Rails
7373
# paths.app.controllers = "app/controllers"
7474
# paths.app.helpers = "app/helpers"
7575
# paths.app.models = "app/models"
76-
# paths.app.metals = "app/metal"
7776
# paths.app.views = "app/views"
7877
# paths.lib = "lib"
7978
# paths.lib.tasks = "lib/tasks"
@@ -202,10 +201,6 @@ def eager_load!
202201
end
203202
end
204203

205-
initializer :add_metals do |app|
206-
app.metal_loader.paths.unshift(*paths.app.metals.to_a)
207-
end
208-
209204
initializer :load_config_initializers do
210205
paths.config.initializers.to_a.sort.each do |initializer|
211206
load(initializer)

railties/lib/rails/engine/configuration.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def paths
1919
paths.app.helpers "app/helpers", :eager_load => true
2020
paths.app.models "app/models", :eager_load => true
2121
paths.app.mailers "app/mailers", :eager_load => true
22-
paths.app.metals "app/metal", :eager_load => true
2322
paths.app.views "app/views"
2423
paths.lib "lib", :load_path => true
2524
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"

railties/lib/rails/generators/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def self.base_name
288288
end
289289

290290
# Removes the namespaces and get the generator name. For example,
291-
# Rails::Generators::MetalGenerator will return "metal" as generator name.
291+
# Rails::Generators::ModelGenerator will return "model" as generator name.
292292
#
293293
def self.generator_name
294294
@generator_name ||= begin

railties/lib/rails/generators/rails/metal/USAGE

Lines changed: 0 additions & 8 deletions
This file was deleted.

railties/lib/rails/generators/rails/metal/metal_generator.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

railties/lib/rails/generators/rails/metal/templates/metal.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

railties/lib/rails/tasks/framework.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace :rails do
3737
project_templates = "#{Rails.root}/lib/templates"
3838

3939
default_templates = { "erb" => %w{controller mailer scaffold},
40-
"rails" => %w{controller helper metal scaffold_controller stylesheets} }
40+
"rails" => %w{controller helper scaffold_controller stylesheets} }
4141

4242
default_templates.each do |type, names|
4343
local_template_type_dir = File.join(project_templates, type)

0 commit comments

Comments
 (0)