How to share common code between methods?


#1

To prevent code repetition i would want to share code between methods.

Can we do includes in MIQ?


#2

Natively, no. You can do some dirty eval on text variables passed through collect or state vars.

However, I think something might be coming. @mkanoor, any hint on this ?


#3

We are waiting for UI changes and we would be able to embed other methods into an ruby method. The embed method backend support was added via PR https://github.com/ManageIQ/manageiq-automation_engine/pull/16


#4

We have been packaging up our shared code into our own gems and distributing them to the appliances. Since Automate runs in a clean environment, the gems are available there. Here is an example of one we created for reusing some common code: https://github.com/ewannema/miq_dev_util

Note that the gems are not available from rails console on an appliance for interactive development. You can look at adding them to your appliance’s Gemfile (or a dev Gemfile) so it works, but you are likely to run into issues with the generated Gemfile.lock during upgrades. I would personally avoid this anywhere, but a dedicated dev server.


#5

ok thanks