提交 81cfdf24 编写于 作者: A Aaron Patterson

stop using @_env in the controller instance

Actions are processed through `dispatch`, so they should have the
request set on them before any user land code can be executed.  Lets
stop setting _env on the controller, and give access to it through the
`env` method.
上级 2a3c47ff
......@@ -252,7 +252,7 @@ def self.without_modules(*modules)
# Define some internal variables that should not be propagated to the view.
PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + [
:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
:@_status, :@_headers, :@_params, :@_response, :@_request,
:@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout ]
def _protected_ivars # :nodoc:
......
......@@ -119,7 +119,7 @@ class Metal < AbstractController::Base
attr_internal_writer :env
def env
@_env ||= {}
@_request.env
end
# Returns the last part of the controller's name, underscored, without the ending
......@@ -215,8 +215,7 @@ def dispatch(name, request) #:nodoc:
def set_request!(request) #:nodoc:
@_request = request
@_env = request.env
@_env['action_controller.instance'] = self
@_request.controller_instance = self
end
def to_a #:nodoc:
......
......@@ -134,6 +134,14 @@ def request_method=(request_method) #:nodoc:
end
end
def controller_instance # :nodoc:
env['action_controller.instance'.freeze]
end
def controller_instance=(controller) # :nodoc:
env['action_controller.instance'.freeze] = controller
end
def show_exceptions? # :nodoc:
# We're treating `nil` as "unset", and we want the default setting to be
# `true`. This logic should be extracted to `env_config` and calculated
......
......@@ -378,7 +378,7 @@ def process(method, path, params: nil, headers: nil, env: nil, xhr: false)
@html_document = nil
@url_options = nil
@controller = session.last_request.env['action_controller.instance']
@controller = @request.controller_instance
response.status
end
......
......@@ -502,7 +502,7 @@ current context:
(byebug) instance_variables
[:@_action_has_layout, :@_routes, :@_headers, :@_status, :@_request,
:@_response, :@_env, :@_prefixes, :@_lookup_context, :@_action_name,
:@_response, :@_prefixes, :@_lookup_context, :@_action_name,
:@_response_body, :@marked_for_same_origin_verification, :@_config]
```
......@@ -533,7 +533,7 @@ And then ask again for the instance_variables:
```
(byebug) instance_variables
[:@_action_has_layout, :@_routes, :@_headers, :@_status, :@_request,
:@_response, :@_env, :@_prefixes, :@_lookup_context, :@_action_name,
:@_response, :@_prefixes, :@_lookup_context, :@_action_name,
:@_response_body, :@marked_for_same_origin_verification, :@_config,
:@articles]
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册