I want to add methods to my datamodel so I need a way to specify them inside my tdd data file(s). For example having a tdd data file containing two scalars :
a: 1
b: 1
I would like to add a method area which multiplies them.
Is this even possible and if so how do I achieve this?
So let's say you have
MyUtilsthat has afoo()and abar()methods, and you want to access those in the templates.You can add an arbitrary Java objects to the model using the
evaldata loader indata, likemyUtils: eval('new com.example.MyUtils()'). Then you can issuemyUtils.foo()in the templates. But, you wanted to add the methods at top level. That's also possible. Both inevaland in a customDataLoader(whichever you want to use) you have access toengine, thefmpp.Engineobject. And then you can pull this trick:Then you add that
Maptodatawithout a name. (If you add aMaptodatawithout a name, its keys become top-level variables.)Certainly it can be polished to be nicer, like find methods you want automatically, etc. Plus I did not try this above (so typos are possible). But this is the basic idea. (I guess it would be practical if FMPP had a data loader that loads the static methods of a class... But, right now it doesn't have that.)