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

Add Optional Context Contract / Verification capability #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sufyanadam
Copy link

Add a needs_context :key1, :key2, :key3... method to
support basic context contract verification / checking.

By including the ContextValidation module in your interactor
class, you get to declare what items in the context are
actually required for the interactor to work correctly.

If someone tries to use an interactor without passing it
any one of the required items, an error is raised.

Add a `needs_context :key1, :key2, :key3...` method to
support basic context contract verification / checking.

By including the `ContextValidation` module in your interactor
class, you get to declare what items in the context are
actually required for the interactor to work correctly.

If someone tries to use an interactor without passing it
any one of the required items, an error is raised.
@timlawrenz
Copy link

timlawrenz commented Jan 27, 2022

We use https://gist.github.com/timlawrenz/b37f2f37cc4eaf520c979800fa9ae42a as a base class that every interactor inherits.
I like your version because it doesn't create a dependency on ActiveModel::Validations.
Did you consider delegating listed arguments to the context?
I was also thinking about adding a returns method for documentation purposes. That way, we could build written documentation automatically.

Copy link

@smridge smridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely found this helpful in an application I worked with quite a bit 👌🏻👍🏻

@sufyanadam
Copy link
Author

thanks @smridge ! 👍

@yorsant
Copy link

yorsant commented Sep 6, 2023

Is this gem still maintained? An approved PR has been open for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants