Configurable routes

15 views
Skip to first unread message

ingo...@gmail.com

unread,
Jul 28, 2015, 4:07:43 PM7/28/15
to Lita
Hi all,

I need to create a route the pattern of which needs to be configurable. The documentation for the :loaded event states that "This can be used as a hook point for handlers to define routes that depend on user configuration not known until runtime", so I tried the following:

on(:loaded) do
MyHandler.route config.my_pattern, :my_method, ...
end

However, it this appears to cause the route to be created multiple times (in my specs, I can see that using robot.handlers.first.routes). Is this not the way to do this? If not, what is?

Thanks for any hint!
Ingo

Jimmy Cuadra

unread,
Jul 28, 2015, 5:15:37 PM7/28/15
to ingo...@gmail.com, Lita
Hi Ingo,

I've done this in a few of my handlers. You're on the right track. I did it by having a method call that defines all the routes instead of having them inline in the class body, so that all the routes can be cleared and then regenerated for each test case:

before do
described_class.routes.clear
subject.define_routes
end

Take a look at lita-karma for an example of this. I'm not super happy with the modification of global state in order to do this. There is probably something we can do to make this pattern easier in a future version of Lita.

Jimmy
--
You received this message because you are subscribed to the Google Groups "Lita" group.
To unsubscribe from this group and stop receiving emails from it, send an email to litaio+un...@googlegroups.com.
To post to this group, send email to lit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ingo Weiss

unread,
Jul 30, 2015, 5:51:37 PM7/30/15
to Lita, ingo...@gmail.com, jimmy...@gmail.com
Thanks, Jimmy - clearing and re-defining routes in the 'before' block worked well!

Ingo
Reply all
Reply to author
Forward
0 new messages