Snowfakery
Snowfakery copied to clipboard
Document ObjectRow for Plugins usage
We are trying to implement a more complex use case than the summation plugin: we need to return a collection of objects that have their sum of field field_1 equal to a certain amount and the sum of field field_2 equal to another amount.
I imagine this can be done using a plugin that returns ObjectRow like so, but this is not clear nor documented, has anyone done anything like that?
https://gist.github.com/edmondo1984/d3219e93edb38b987fd927f274162a85
It's a bit hard for me to give you very crisp advice because your use case is still slightly fuzzy for me, but in general I'd say:
-
Yes the plugin is stateful but you need to use attributes on the "self" variable to manipulate its state. So it would be more like self._index +=1
-
There is another grouping object which is probably more appropriate than an ObjectRow, which is a PluginResult. You could return a small PluginResult subclass that has values total_field_1 and total_field_2.
-
Actually you probably don't even need a subclass. There is a short-cut for making simple PluginResults.
return PluginResult({"a": "b"})
Then if you assign that object to __foo you can refer to __foo.a to get b.
Does that help?
I'll leave the issue open because there are still some gaps in documentation.
I am a little confused, how would I return a different element each time? Can you explain the difference between ObjectRow and PluginResult?
If you could write what you want as a Python program (not a plugin) that just prints out the values you want, then I could help you transform it into a plugin.
#777 feature might meet your needs.