HomePhorge

(#6749) add a shim around the action implementation.
4d23d60fc331Unpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

(#6749) add a shim around the action implementation.

To present a pleasant Ruby API to folks invoking actions we want to have
default values for the trailing 'options' argument, and to be able to pass a
block to the code to allow yield to work.

Given limitations of Ruby 1.8 regarding blocks, we can't use either of those
because the block slot is bound at declaration time, and you can't give
optional arguments.

To work around this we inject, using eval, a full regular Ruby method into the
final block of code. This can provide the default argument at the end in an
intelligent way (albeit by emulating what the interpreter would do).

This doesn't solve the yield problem, but the same method can pass the block
explicitly, and allows other hooks to be injected, which makes it easier to do
smarter things in future...

Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>

Details

Provenance
Daniel Pittman <daniel@puppetlabs.com>Authored on
vanmeeuwenPushed on Jun 2 2015, 2:22 PM
Parents
rPUeb4c4fbdc395: (#6749) Start porting existing strings to the options API.
Branches
Unknown
Tags
Unknown

Event Timeline

Daniel Pittman <daniel@puppetlabs.com> committed rPU4d23d60fc331: (#6749) add a shim around the action implementation. (authored by Daniel Pittman <daniel@puppetlabs.com>).Apr 4 2011, 10:32 PM