Parent

Included Modules

Class Index [+]

Quicksearch

ActionDispatch::Reloader

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 # has been called on the response body. This is important for streaming responses such as the following:

    self.response_body = lambda { |response, output|
      # code here which refers to application models
    }

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.

Public Class Methods

cleanup!() click to toggle source

Execute all cleanup callbacks.

    # File lib/action_dispatch/middleware/reloader.rb, line 52
52:     def self.cleanup!
53:       new(nil).cleanup!
54:     end
new(app, condition=nil) click to toggle source
    # File lib/action_dispatch/middleware/reloader.rb, line 56
56:     def initialize(app, condition=nil)
57:       @app = app
58:       @condition = condition || lambda { true }
59:       @validated = true
60:     end
prepare!() click to toggle source

Execute all prepare callbacks.

    # File lib/action_dispatch/middleware/reloader.rb, line 47
47:     def self.prepare!
48:       new(nil).prepare!
49:     end
to_cleanup(*args, &block) click to toggle source

Add a cleanup callback. Cleanup callbacks are run after each request is complete (after # is called on the response body).

    # File lib/action_dispatch/middleware/reloader.rb, line 42
42:     def self.to_cleanup(*args, &block)
43:       set_callback(:cleanup, *args, &block)
44:     end
to_prepare(*args, &block) click to toggle source

Add a prepare callback. Prepare callbacks are run before each request, prior to ActionDispatch::Callback’s before callbacks.

    # File lib/action_dispatch/middleware/reloader.rb, line 36
36:     def self.to_prepare(*args, &block)
37:       set_callback(:prepare, *args, &block)
38:     end

Public Instance Methods

call(env) click to toggle source
    # File lib/action_dispatch/middleware/reloader.rb, line 62
62:     def call(env)
63:       @validated = @condition.call
64:       prepare!
65:       response = @app.call(env)
66:       response[2] = ActionDispatch::BodyProxy.new(response[2]) { cleanup! }
67:       response
68:     rescue Exception
69:       cleanup!
70:       raise
71:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.