Basically, this is a separate middleware stack executed at arbitrary points during routing. Except that it doesn't operate as a middleware stack. Consider a middleware such as:
class M2
def initialize(app)
@app = app
end
def call(env)
@app.call(env.merge('baz'=>'quuz'))
end
end
This change to `env` is lost. Also consider a change where you are using a middleware that modifies the response:
class M2
def initialize(app)
@app = app
end
def call(env)
res = @app.call(env)
def (res[2]).each
super{|s| yield s.upcase}
end
res
end
end
This pipeline plugin doesn't do what is expected with this middleware.
If you actually want something like this in Roda, you need separate rack applications for the branches which need separate middleware stacks. Those rack applications can also be Roda applications. You can then use r.run to dispatch to these apps:
class API < Roda
use M1
route do |r|
'foo'
end
end
class Web < Roda
use M1
use M2
route do |r|
'bar'
end
end
class App < Roda
route do |r|
r.root do
'root'
end
r.on('foo') do
r.run API
end
r.on('bar') do
r.run Web
end
end
end
If you have many similar blocks like this using r.run, you may want to look into the multi_run plugin.
Thanks,
Jeremy