Snowfakery icon indicating copy to clipboard operation
Snowfakery copied to clipboard

Document ObjectRow for Plugins usage

Open edmondop opened this issue 3 years ago • 3 comments

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

 

edmondop avatar Mar 16 '21 08:03 edmondop

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:

  1. 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

  2. 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.

  3. 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.

prescod avatar Mar 21 '21 16:03 prescod

I am a little confused, how would I return a different element each time? Can you explain the difference between ObjectRow and PluginResult?

edmondop avatar Mar 21 '21 18:03 edmondop

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.

prescod avatar Mar 21 '21 19:03 prescod

#777 feature might meet your needs.

prescod avatar May 05 '23 21:05 prescod