[Enhancement] Add declarative syntax for delegated context variables
williampollet opened this issue · comments
Sometimes we instantiate objects manually in the actor, from a main input. To do that, most of the time we override the call method in the players, or create attr_readers
from the main input.
What do you think about adding a declarative syntax to avoid being forced to override call
in such use cases ?
An actor looking like this
module Projects
class Confirm < Actor
input :project, type: Project
def call
result.owner = project.owner
result.rewards = project.rewards
super
end
play ConfirmOwner, ConfirmRewards, ConfirmProject
end
end
Could be simplified like this for instance :
module Projects
class Confirm < Actor
input :project, type: Project
declare :owner, :rewards, on: :project
play ConfirmOwner, ConfirmRewards, ConfirmProject
end
end
Hey @williampollet \o/
I think in that case I would go with the more versatile lambdas, that allows to be inserted in between actors, e.g.:
module Projects::Confirm < Actor
input :project, type: Project
play -> result {
result.owner = result.project.owner
result.rewards = result.project.rewards
},
ConfirmOwner,
ConfirmRewards,
ConfirmProject,
-> result { result.moderator = result.project.moderator },
NotifyModerator
end
Adding a new DSL to declare
this would be a bit too much for this gem I think.