Phoenix-like `pipeline` plugin for Roda

16 views
Skip to first unread message

Василий Колесников

unread,
Jun 30, 2021, 7:21:26 PM6/30/21
to Roda
Hi Jeremy and all!

What do you think about the subject? Would it be useful to have such plugin?

Jeremy Evans

unread,
Jun 30, 2021, 7:55:17 PM6/30/21
to ruby...@googlegroups.com
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

Vasily Kolesnikov

unread,
Jun 30, 2021, 8:15:06 PM6/30/21
to ruby...@googlegroups.com
Now, I see the problems. Thanks!

--
You received this message because you are subscribed to the Google Groups "Roda" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-roda+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-roda/CADGZSSd1bUxBroW1NbZ2fX3dToUiX6UaUc_4idtBDY%2B%3DrGwuKw%40mail.gmail.com.
--
С уважением
Василий Колесников
Reply all
Reply to author
Forward
0 new messages