interactor icon indicating copy to clipboard operation
interactor copied to clipboard

Add Optional Context Contract / Verification capability

Open sufyanadam opened this issue 3 years ago • 3 comments

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.

sufyanadam avatar Jan 24 '22 04:01 sufyanadam

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.

timlawrenz avatar Jan 27 '22 18:01 timlawrenz

thanks @smridge ! 👍

sufyanadam avatar Nov 12 '22 22:11 sufyanadam

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

yorsant avatar Sep 06 '23 15:09 yorsant