Skip to content

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