Got a weird one... I sometimes have organizers that use iterate and need to get the promised values from each iteration into something in the context.
Here's a dummy example:
# In an imaginary organizer called ApplyRatingsToBook
def self.actions
[
add_to_context(book_ratings: []),
iterate(:ratings, [
Book::ApplyRating # <- thus guy expects a `Book` and `Rating`, and promises a 'BookRating' for e.g.
execute(->(ctx) { ctx.book_ratings << ctx.book_rating }) # I'm collecting all `book_ratings` for something outside of the organizer
]
end
The surprising behaviour
I would assume that when I add something to the context using add_to_context like above, it's available as an accessor in much the same way that expects and promises works, except it is only accessible as a key on the Context object which is ultimately returned from the organizer.
A way forward
If you agree with the above, I'd love to put together a PR that updates the Organizer add_to_context feature to turn it into a context accessor as well as the standard key.
Hiya @adomokos !
Got a weird one... I sometimes have organizers that use
iterate
and need to get the promised values from each iteration into something in the context.Here's a dummy example:
The surprising behaviour
I would assume that when I add something to the context using
add_to_context
like above, it's available as an accessor in much the same way thatexpects
andpromises
works, except it is only accessible as a key on theContext
object which is ultimately returned from the organizer.A way forward
If you agree with the above, I'd love to put together a PR that updates the Organizer
add_to_context
feature to turn it into a context accessor as well as the standard key.Let me know :) and thanks again :)