Class: ActionController::Metal

Inherits:
AbstractController::Base show all
Defined in:
actionpack/lib/action_controller/metal.rb

Overview

ActionController::Metal provides a way to get a valid Rack application from a controller.

In AbstractController, dispatching is triggered directly by calling #process on a new controller. ActionController::Metal provides an #action method that returns a valid Rack application for a given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails router, can dispatch directly to the action returned by FooController.action(:index).

Class Method Summary

Instance Method Summary

Methods inherited from AbstractController::Base

abstract!, abstract?, action_methods, descendants, hidden_actions, inherited, internal_methods, #process

Constructor Details

- (Metal) initialize

A new instance of Metal



54
55
56
57
# File 'actionpack/lib/action_controller/metal.rb', line 54

def initialize(*)
  @_headers = {}
  super
end

Class Method Details

+ (Object) action(name)

Return a rack endpoint for the given action. Memoize the endpoint, so multiple calls into MyController.action will return the same object for the same action.

Parameters

action<#to_s>:An action name

Returns

Proc:A rack application


121
122
123
# File 'actionpack/lib/action_controller/metal.rb', line 121

def self.action(name)
  ActionEndpoint.for(self, name, middleware_stack)
end

+ (Object) controller_name

Returns the last part of the controller’s name, underscored, without the ending “Controller”. For instance, MyApp::MyPostsController would return “my_posts” for controller_name

Returns

String



22
23
24
# File 'actionpack/lib/action_controller/metal.rb', line 22

def self.controller_name
  @controller_name ||= controller_path.split("/").last
end

+ (Object) controller_path

Returns the full controller name, underscored, without the ending Controller. For instance, MyApp::MyPostsController would return “my_app/my_posts” for controller_name.

Returns

String



37
38
39
# File 'actionpack/lib/action_controller/metal.rb', line 37

def self.controller_path
  @controller_path ||= name && name.sub(/Controller$/, '').underscore
end

+ (Object) middleware



108
109
110
# File 'actionpack/lib/action_controller/metal.rb', line 108

def self.middleware
  middleware_stack
end

+ (Object) use(*args)



104
105
106
# File 'actionpack/lib/action_controller/metal.rb', line 104

def self.use(*args)
  middleware_stack.use(*args)
end

Instance Method Details

- (Object) call(name, env)

:api: private



72
73
74
75
76
# File 'actionpack/lib/action_controller/metal.rb', line 72

def call(name, env)
  @_env = env
  process(name)
  to_a
end

- (Object) content_type=(type)

Basic implementations for content_type=, location=, and headers are provided to reduce the dependency on the RackConvenience module in Renderer and Redirector.



63
64
65
# File 'actionpack/lib/action_controller/metal.rb', line 63

def content_type=(type)
  headers["Content-Type"] = type.to_s
end

- (Object) controller_name

Delegates to the class’ #controller_name



27
28
29
# File 'actionpack/lib/action_controller/metal.rb', line 27

def controller_name
  self.class.controller_name
end

- (Object) controller_path

Delegates to the class’ #controller_path



42
43
44
# File 'actionpack/lib/action_controller/metal.rb', line 42

def controller_path
  self.class.controller_path
end

- (Object) location=(url)



67
68
69
# File 'actionpack/lib/action_controller/metal.rb', line 67

def location=(url)
  headers["Location"] = url
end

- (Object) to_a

:api: private



79
80
81
# File 'actionpack/lib/action_controller/metal.rb', line 79

def to_a
  response ? response.to_a : [status, headers, response_body]
end