Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[This is not an issue per se, rather a question] How to pass in positional arguments, and no keyword arguments? #75

Closed
alfuken opened this issue Jul 22, 2022 · 3 comments
Labels
question Further information is requested

Comments

@alfuken
Copy link

alfuken commented Jul 22, 2022

How to pass in positional arguments, and no keyword arguments? And at the same time keep the input validation, i.e. input :user, type: User. Is that possible to do here? And, preferably, painlessly. :)

@sunny
Copy link
Owner

sunny commented Jul 22, 2022

Hi @alfuken! No, positional arguments are not possible on actors.

One way you could make it work for your use-case would be to create a new class method that turns positional arguments into named arguments.

E.g.:

class Pay < Actor
  input :user, type: User

  def self.trigger(user)
    call(user: user)
  end

  # Or even
  def self.call(user)
    super(user: user)
  end

  def call
    puts "Paying #{user.id}…"
  end
end

Pay.trigger(User.first)
# => Paying 32…
Pay.call(User.first)
# => Paying 32…

@alfuken
Copy link
Author

alfuken commented Jul 22, 2022

The use-case itself is about dynamic steps composition:

conveyor = Conveyor.find(x)
result = conveyor.steps.split(',').map(&:constantize).reduce(&:>>).(JSON.parse(conveyor.input))

Currently steps are just PORO, but the input validation is really something that could be improved, hence Actor :)

self.call with super is actually a good example, and it solves the question. Thanks! 👍

PS. Would be nice to see this in a readme too, in some kind of FAQ or smth, in case someone else has a similar question.

@alfuken alfuken closed this as completed Jul 22, 2022
@sunny
Copy link
Owner

sunny commented Jul 22, 2022

Good idea. As a first step I’ve started a wiki with a link pointing to this issue/question :)

@sunny sunny added the question Further information is requested label Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants