# Portable monkey patch for reloading constants before hitting metal # applications. More details in the introduction article at: # # http://roman.flucti.com/reloading-rails-metal-applications # Rails::Rack::Metal.class_eval do # Prevent Metal from further require'ing source files, in order to let # AS::Dependencies handle constants. class << self def require(*args) end end # Remove already loaded metal constants so that they get loaded by # AS::Dependencies the next time they are needed. metals.grep(Module).each do |mod| $".delete(mod.name.underscore + ".rb") ActiveSupport::Dependencies.remove_constant(mod.name) end # Force metal constants to be reloaded before each request. def call_with_reload(*args, &block) @metals.clear RELOADER.reload do self.class.metals.each { |app| @metals[app] = true } call_without_reload(*args, &block) end end alias_method_chain :call, 'reload' # Expose the reloading mechanism via a stripped down Dispatcher instance. bare_dispatcher = Class.new(ActionController::Dispatcher) do def initialize end def reload reload_application begin yield ensure cleanup_application if respond_to? :cleanup_application end end end RELOADER = bare_dispatcher.new end if Rails.env.development?