module Roda::RodaPlugins::MultiRun::ClassMethods
def freeze
and to speed up subsequent calls.
Convert app blocks into apps by calling them, in order to force autoloads
def freeze app_blocks = opts[:multi_run_app_blocks] apps = opts[:multi_run_apps] app_blocks.each do |prefix, block| apps[prefix] = block.call end app_blocks.clear.freeze apps.freeze self::RodaRequest.refresh_multi_run_regexp! super end
def multi_run_apps
Hash storing rack applications to dispatch to, keyed by the prefix
def multi_run_apps opts[:multi_run_apps] end
def run(prefix, app=nil, &block)
a block or an app is provided, any stored route for the prefix is
there is a request for the route to get the app to call. If neither
r.multi_run is called. If a block is given, it is called every time
Add a rack application to dispatch to for the given prefix when
def run(prefix, app=nil, &block) prefix = prefix.to_s if app raise Roda::RodaError, "cannot provide both app and block to Roda.run" if block opts[:multi_run_apps][prefix] = app opts[:multi_run_app_blocks].delete(prefix) elsif block opts[:multi_run_apps].delete(prefix) opts[:multi_run_app_blocks][prefix] = block else opts[:multi_run_apps].delete(prefix) opts[:multi_run_app_blocks].delete(prefix) end self::RodaRequest.refresh_multi_run_regexp! end