lib/roda/plugins/multi_run.rb in roda-3.50.0 vs lib/roda/plugins/multi_run.rb in roda-3.51.0
- old
+ new
@@ -43,10 +43,13 @@
# being the multi_route plugin keeps all routing subtrees in the same Roda app/class,
# while multi_run dispatches to other rack apps. If you want to isolate your routing
# subtrees, multi_run is a better approach, but it does not let you set instance
# variables in the main Roda app and have those instance variables usable in
# the routing subtrees.
+ #
+ # To handle development environments that reload code, you can call the
+ # +run+ class method without an app to remove dispatching for the prefix.
module MultiRun
# Initialize the storage for the dispatched applications
def self.configure(app)
app.opts[:multi_run_apps] ||= {}
end
@@ -65,11 +68,15 @@
opts[:multi_run_apps]
end
# Add a rack application to dispatch to for the given prefix when
# r.multi_run is called.
- def run(prefix, app)
- multi_run_apps[prefix.to_s] = app
+ def run(prefix, app=nil)
+ if app
+ multi_run_apps[prefix.to_s] = app
+ else
+ multi_run_apps.delete(prefix.to_s)
+ end
self::RodaRequest.refresh_multi_run_regexp!
end
end
module RequestClassMethods