module Roda::RodaPlugins::MultiRun::ClassMethods

  1. lib/roda/plugins/multi_run.rb

Methods

Public Instance

  1. freeze
  2. multi_run_apps
  3. run

Public Instance methods

freeze()

Convert app blocks into apps by calling them, in order to force autoloads and to speed up subsequent calls. Freeze the multi_run apps so that there can be no thread safety issues at runtime.

[show source]
   # File lib/roda/plugins/multi_run.rb
76 def freeze
77   app_blocks = opts[:multi_run_app_blocks]
78   apps = opts[:multi_run_apps]
79   app_blocks.each do |prefix, block|
80     apps[prefix] = block.call
81   end
82   app_blocks.clear.freeze
83   apps.freeze
84   self::RodaRequest.refresh_multi_run_regexp!
85   super
86 end
multi_run_apps()

Hash storing rack applications to dispatch to, keyed by the prefix for the application.

[show source]
   # File lib/roda/plugins/multi_run.rb
90 def multi_run_apps
91   opts[:multi_run_apps]
92 end
run(prefix, app=nil, &block)

Add a rack application to dispatch to for the given prefix when r.multi_run is called. If a block is given, it is called every time there is a request for the route to get the app to call. If neither a block or an app is provided, any stored route for the prefix is removed. It is an error to provide both an app and block in the same call.

[show source]
    # File lib/roda/plugins/multi_run.rb
 99 def run(prefix, app=nil, &block)
100   prefix = prefix.to_s
101   if app 
102     raise Roda::RodaError, "cannot provide both app and block to Roda.run" if block
103     opts[:multi_run_apps][prefix] = app
104     opts[:multi_run_app_blocks].delete(prefix)
105   elsif block
106     opts[:multi_run_apps].delete(prefix)
107     opts[:multi_run_app_blocks][prefix] = block
108   else
109     opts[:multi_run_apps].delete(prefix)
110     opts[:multi_run_app_blocks].delete(prefix)
111   end
112   self::RodaRequest.refresh_multi_run_regexp!
113 end