Sha256: 0df631f6c89731dc5fa1e5df03e64fbbc69db4027f4f1da26155ba5c22461a1b

Contents?: true

Size: 1.51 KB

Versions: 63

Compression:

Stored size: 1.51 KB

Contents

require 'thread'

module ActionController
  class Reloader
    @@default_lock = Mutex.new
    cattr_accessor :default_lock

    class BodyWrapper
      def initialize(body, lock)
        @body = body
        @lock = lock
      end

      def close
        @body.close if @body.respond_to?(:close)
      ensure
        Dispatcher.cleanup_application
        @lock.unlock
      end

      def method_missing(*args, &block)
        @body.send(*args, &block)
      end

      def respond_to?(symbol, include_private = false)
        symbol == :close || @body.respond_to?(symbol, include_private)
      end
    end

    def self.run(lock = @@default_lock)
      lock.lock
      begin
        Dispatcher.reload_application
        status, headers, body = yield
        # We do not want to call 'cleanup_application' in an ensure block
        # because the returned Rack response body may lazily generate its data. This
        # is for example the case if one calls
        #
        #   render :text => lambda { ... code here which refers to application models ... }
        #
        # in an ActionController.
        #
        # Instead, we will want to cleanup the application code after the request is
        # completely finished. So we wrap the body in a BodyWrapper class so that
        # when the Rack handler calls #close during the end of the request, we get to
        # run our cleanup code.
        [status, headers, BodyWrapper.new(body, lock)]
      rescue Exception
        lock.unlock
        raise
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 13 rubygems

Version Path
actionpack-2.3.18 lib/action_controller/reloader.rb
actionpack_csi-2.3.5.p8 lib/action_controller/reloader.rb
actionpack-2.3.17-rack-upgrade-2.3.17 lib/action_controller/reloader.rb
actionpack-2.3.17 lib/action_controller/reloader.rb
actionpack_csi-2.3.5.p7 lib/action_controller/reloader.rb
actionpack_csi-2.3.5.p6 lib/action_controller/reloader.rb
actionpack-2.3.16 lib/action_controller/reloader.rb
actionpack-rack-upgrade-2-2.3.16 lib/action_controller/reloader.rb
actionpack-rack-upgrade-2-2.3.15 lib/action_controller/reloader.rb
actionpack-2.3.15 lib/action_controller/reloader.rb
actionpack-rack-upgrade-2.3.16 lib/action_controller/reloader.rb
actionpack-rack-upgrade-2.3.15 lib/action_controller/reloader.rb
actionpack-rack-upgrade-2.3.14 lib/action_controller/reloader.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/actionpack-2.3.14/lib/action_controller/reloader.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/actionpack-2.3.12/lib/action_controller/reloader.rb
actionpack-2.3.14 lib/action_controller/reloader.rb
kajam-1.0.3.rc2 vendor/rails/actionpack/lib/action_controller/reloader.rb
actionpack-2.3.12 lib/action_controller/reloader.rb
radiant-1.0.0.rc2 vendor/rails/actionpack/lib/action_controller/reloader.rb
radiant-1.0.0.rc1 vendor/rails/actionpack/lib/action_controller/reloader.rb