Class: ActionDispatch::Reloader
- Defined in:
- lib/action_dispatch/middleware/reloader.rb
Overview
ActionDispatch::Reloader provides prepare and cleanup callbacks, intended to assist with code reloading during development.
Prepare callbacks are run before each request, and cleanup callbacks after each request. In this respect they are analogs of ActionDispatch::Callback’s before and after callbacks. However, cleanup callbacks are not called until the request is fully complete – that is, after #close has been called on the response body. This is important for streaming responses such as the following:
self.response_body = -> (response, output) do
# code here which refers to application models
end
Cleanup callbacks will not be called until after the response_body lambda is evaluated, ensuring that it can refer to application models and other classes before they are unloaded.
By default, ActionDispatch::Reloader is included in the middleware stack only in the development environment; specifically, when config.cache_classes
is false. Callbacks may be registered even when it is not included in the middleware stack, but are executed only when ActionDispatch::Reloader.prepare!
or ActionDispatch::Reloader.cleanup!
are called manually.
Class Attribute Summary collapse
-
.default_reloader ⇒ Object
:nodoc:.
Class Method Summary collapse
- .cleanup! ⇒ Object
- .prepare! ⇒ Object
- .to_cleanup(*args, &block) ⇒ Object
- .to_prepare(*args, &block) ⇒ Object
Methods inherited from Executor
Constructor Details
This class inherits a constructor from ActionDispatch::Executor
Class Attribute Details
.default_reloader ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/action_dispatch/middleware/reloader.rb', line 44 def default_reloader @default_reloader end |
Class Method Details
.cleanup! ⇒ Object
39 40 41 |
# File 'lib/action_dispatch/middleware/reloader.rb', line 39 def self.cleanup! default_reloader.reload! end |
.prepare! ⇒ Object
35 36 37 |
# File 'lib/action_dispatch/middleware/reloader.rb', line 35 def self.prepare! default_reloader.prepare! end |
.to_cleanup(*args, &block) ⇒ Object
31 32 33 |
# File 'lib/action_dispatch/middleware/reloader.rb', line 31 def self.to_cleanup(*args, &block) ActiveSupport::Reloader.to_complete(*args, &block) end |
.to_prepare(*args, &block) ⇒ Object
27 28 29 |
# File 'lib/action_dispatch/middleware/reloader.rb', line 27 def self.to_prepare(*args, &block) ActiveSupport::Reloader.to_prepare(*args, &block) end |