I'm using Blockenspiel to create a DSL with Ruby. It works great and solves a lot of my problems, but I encountered the following problem that is not strictly related to Blockenspiel.
Suppose I have a DSL that looks like this:
dish do
name = 'Pizza'
ingredients = ...
nutrition_facts = ...
end
dish do
name = 'Doner'
ingredients = ...
nutrition_facts = ...
end
Now I have a menu compiler which takes the dishes and compiles them into a menu. The compiler should now be able to compile multiple menu files, so it has setup and clear a global context. This should preferably happen in parallel.
I found out that sinatra uses class variables, but this has the consequence that it can only do sequential processing and that you have to clear the class variables when you want to compile a new menu. An alternative would be to use global variables.
I would prefer to evaluate the DSL methods within the scope of an object, so that there's no global context and I could compile the menus in parallel, but the last time I tried this, I encountered some problems when declaring (helper-)methods in the menu file.
Which methods are possible? What is the recommended way to do this?