lml / lev

Ride the rails but don't touch them.
MIT License
2 stars 6 forks source link

added delegates_to capability #16

Closed jpslav closed 9 years ago

jpslav commented 9 years ago

From the new README in this PR:

Delegates

If you have

class BarRoutine
  lev_routine

  def exec(alpha:, beta:)
    # Do work
  end
end

you might have a reason to wrap this routine inside another, in which case you could write:

class FooRoutine
  lev_routine

  uses_routine BarRoutine,
               translations: {
                 outputs: { type: :verbatim },
                 inputs: { type: :verbatim }
               }

  def exec(alpha:, beta:)
    run(BarRoutine, alpha: alpha, beta: beta)
  end
end

or if you use the delegates_to: shortcut, you can instead equivalently wrap BarRoutine with:

class ShorterFooRoutine
  lev_routine delegates_to: BarRoutine
end

When using delegates_to, any express_output value set in the delegated routine is automatically used again by the delegating routine.

jpslav commented 9 years ago

@Dantemss and @joemsak, please take a look

Dantemss commented 9 years ago

Cool PR but maybe it needs some of https://github.com/openstax/exchange/blob/master/lib/lev/delegator.rb?

Dantemss commented 9 years ago

The Exchange stuff allows you to delegate to different routines based on the class of the first argument.

joemsak commented 9 years ago

:+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses: :+1: :sunglasses:

jpslav commented 9 years ago

@Dantemss if you have ideas on how to add that delegator stuff in with a tweak so that the formats are similar, I'd potentially be up for it (maybe in a separate PR written by you :-), e.g.

delegates_to: FooRoutine, for_args: Type1, Type2

or something...

would like it to not just be the first arg (that seems like it might not be that easy to know / read)