Hey all,Is there a good app that is out there that shows a good usage of the multi_route plugin? I’m attempting to use it in my application and it I think my notions of what should be doable are different than what it does.
For instance, Say I have an app that uses multiple roda apps and r.run to dispatch to them, and I want to convert it to use multi_route. This is an off the cuff example, and is representative of what the app I’d like to change to use multi_route.original app : https://gist.github.com/copiousfreetime/5792ee728961d60b56e5multi_route attempted conversion (does not work): https://gist.github.com/copiousfreetime/74eea8d50a666c4b8122
It looks like when you are using multi_route, you must reference the top level App.route method, it doesn’t pass through to the other classes.Also, the context of execution within the route is the top level App, it is not the class where the route is defined, so that means that if you want to call methods within the class of the route you are defining then you need to make the class level methods and pass in a context. So if you had different plugins used in different routing contexts, you need to push them all up into the top level app. Also helper or such, they all end up in the top level app. That basically makes the top level app class a big mess of plugins and helpers which I’m not really a big fan of.
I’ve read http://roda.jeremyevans.net/rdoc/files/doc/conventions_rdoc.html and that doesn’t appear to answer what should be in those ‘routes/a.rb’ etc files. Just the routing block? If that is the case, then were are you putting the classes that implement the business logic at the route termination?Am I even explaining myself well?
On Saturday, December 6, 2014 3:48:02 PM UTC-8, Jeremy Hinegardner wrote:Hey all,Is there a good app that is out there that shows a good usage of the multi_route plugin? I’m attempting to use it in my application and it I think my notions of what should be doable are different than what it does.Unfortunately, all of the large Roda apps where I use multi_route are proprietary apps, so unfortunately I don't have an open source example.
Well, I look forward to the day when we have some large example Roda Apps :-).
For instance, Say I have an app that uses multiple roda apps and r.run to dispatch to them, and I want to convert it to use multi_route. This is an off the cuff example, and is representative of what the app I’d like to change to use multi_route.original app : https://gist.github.com/copiousfreetime/5792ee728961d60b56e5multi_route attempted conversion (does not work): https://gist.github.com/copiousfreetime/74eea8d50a666c4b8122With the multi_route plugin, everything is in the same class. Your example has App and B subclasses of Roda. For this, multi_route won't work. If you want to use multi_route, you need to combine the multiple classes into a single class.
Understood, That matches with the behavior I am seeing.
It looks like when you are using multi_route, you must reference the top level App.route method, it doesn’t pass through to the other classes.Also, the context of execution within the route is the top level App, it is not the class where the route is defined, so that means that if you want to call methods within the class of the route you are defining then you need to make the class level methods and pass in a context. So if you had different plugins used in different routing contexts, you need to push them all up into the top level app. Also helper or such, they all end up in the top level app. That basically makes the top level app class a big mess of plugins and helpers which I’m not really a big fan of.Well, then maybe the multi_route plugin is not what you want to use, and you should stick to using run. Note that there is nothing wrong with using run to dispatch to separate Roda (or other rack) applications.
I was wanting to switch to the multi_route so that there would be just one routing tree. I haven’t benchmarked, and maybe this is something to add to the r10k to understand the speed difference between a single multi_route system layout and a whole bunch of smaller roda apps that are effectively mounted within the routing tree and have sub routing trees of their own.
I was mostly pondering switching to multi_route since that appeared to be the recommended approach for larger applications.
I’ve read http://roda.jeremyevans.net/rdoc/files/doc/conventions_rdoc.html and that doesn’t appear to answer what should be in those ‘routes/a.rb’ etc files. Just the routing block? If that is the case, then were are you putting the classes that implement the business logic at the route termination?Am I even explaining myself well?I think so. Hopefully this example will clear things up:
It may be possible to add another plugin with an API similar to multi_route that works similar to run (multi_run?). Maybe an API like:# app.rbclass App < Rodaplugin :multi_runDir['./routes/*.rb'].each{|f| require f}route do |r|r.multi_runendend# routes/a.rbclass A < AppApp.run("a", self)route do |r|# ...endend# routes/b.rbclass B < AppApp.run("b", self)route do |r|# ...endendSuch a plugin would be a bit slower than multi_route, but would add more separation between the various routing subtrees. Because the routing subtrees are subclasses of the main application (in this example, not actually required), you could add helpers to the main application that would be usable by all of the routing subtrees, but helpers added to a single routing subtree would not affect other routing subtrees. Thoughts on this?
I could go for smething in that range. Some plugin that allows for the ease of organization of multi_route but uses individual roda apps. I’d have to think for a bit.
I have another thought (that is not complete) about how each route terminates in a lambda/block and capturing the context at that point to dispatching to a particular object.
Maybe what I’m thinking of is more if a complete routing tree for the application, and a execution context that changes based upon the current node in the routing tree.
I’m happy to continue with run for the time being. Mostly wanted to make sure I wasn’t doing something wrong wrt multi_route. In any case, it is probably good to think about how an application would look that is based more upon run than multi_route.
enjoy
-jeremy
I’m happy to continue with run for the time being. Mostly wanted to make sure I wasn’t doing something wrong wrt multi_route. In any case, it is probably good to think about how an application would look that is based more upon run than multi_route.
Hello everyone
I am also looking to create a large app, I prefer to separate my app into modules that are self contained and can be easily extracted if need be in the future.
Is there an efficient way to achieve the below layout (you can ignore the naming I'm more interested in the structure).
Any pointer will greatly be appreciated.
The example is adopted from a .Net mvc app layout that I have managed to use successfully to isolate related features into self contained modules which has simplified maintenance and development a lot.
I was impressed by Roda and would love to replicate the same layout, where there are minimal app wide features such as master templates, master styles, master js, master routes etc for features that are cross cutting plus the self contained modules. I had read on the run option but got the impression that it might not be the most efficient.
That is why I wanted to get your opinion on the most efficient/fast way of achieving my type of setup.
When creating the multi_run plugin would you please consider such a modular layout, I have found it to be one of the best ways to keep large apps maintainable, and easy for new dev's to dive into.