module Roda::RodaPlugins::MultiRun::ClassMethods

  1. lib/roda/plugins/multi_run.rb

Methods

Public Instance

  1. freeze
  2. 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
79 def freeze
80   app_blocks = multi_run_app_blocks
81   apps = multi_run_apps
82   app_blocks.each do |prefix, block|
83     apps[prefix] = block.call
84   end
85   app_blocks.clear.freeze
86   apps.freeze
87   self::RodaRequest.refresh_multi_run_regexp!
88   super
89 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
 96 def run(prefix, app=nil, &block)
 97   prefix = prefix.to_s
 98   if app 
 99     raise Roda::RodaError, "cannot provide both app and block to Roda.run" if block
100     multi_run_apps[prefix] = app
101     multi_run_app_blocks.delete(prefix)
102   elsif block
103     multi_run_apps.delete(prefix)
104     multi_run_app_blocks[prefix] = block
105   else
106     multi_run_apps.delete(prefix)
107     multi_run_app_blocks.delete(prefix)
108   end
109   self::RodaRequest.refresh_multi_run_regexp!
110 end