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

[Feature Request] Support in place callbacks #247

Closed
aka-momo opened this issue Oct 4, 2020 · 0 comments · Fixed by #248
Closed

[Feature Request] Support in place callbacks #247

aka-momo opened this issue Oct 4, 2020 · 0 comments · Fixed by #248
Labels
feature New feature or request
Milestone

Comments

@aka-momo
Copy link
Contributor

aka-momo commented Oct 4, 2020

Elevator pitch, describe and sell us your feature request

As a developer,
I want be able to attach callbacks on the organizer's level
so that I be able to re-use interactors in different contexts

Is your feature request related to a problem

I'm always frustrated when I need to use a specific interactor in different contexts.

Sometimes a specific interactor is built to expect a specific input for example user_id while the current context has user object instead, I need to be able to set the user id before the execution of this interactor.

class TestOrganizer < ActiveInteractor::Organizer::Base
  organize do
    add :update_username
    add :find_user_token_by_user_id, before: -> { context.user_id = context.user.id }
    add :baz_interactor
  end
end

Have you considered any alternatives

From the example mentioned above, I can create another command called find_user_token_by_user to expect a user object instead of user_id but it causes unnecessary logic duplication.

Additional Comments

Another use case if to be able to fail context after an execution of a specific interactor only in this context.

class TestOrganizer < ActiveInteractor::Organizer::Base
  organize do
    add :foo_interactor
    add :bar_interactor, after: -> { context.fail! if context.something == false }
    add :baz_interactor
  end
end
@aka-momo aka-momo added the feature New feature or request label Oct 4, 2020
@aka-momo aka-momo mentioned this issue Oct 4, 2020
3 tasks
@aaronmallen aaronmallen added this to the v1.1.0 milestone Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants