-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Proposal for new Context pattern #74
Comments
I definitely think the new proposed architecture is nicer. Providing a way for the user to specify their own context class is going to make your library more extensible and powerful, and saves me as an end user from monkey patching your code anyway. I also think I do prefer the sub-classed |
I think it would also be beneficial to allow for an interactor to define it's own context class to allow for classes that don't meet the expected naming convention. class User < ActiveRecord::Base
end
class AuthenticateUser < ActiveInteractor::Base
self.context_class = User
end |
Great idea
…On Wed, Oct 16, 2019 at 5:50 PM Aaron Allen ***@***.***> wrote:
I think it would also be beneficial to allow for an interactor to define
it's own context class to allow for classes that don't meet the expected
naming convention.
class User < ActiveRecord::Baseend
class MyInteractor < ActiveInteractor::Base
self.context_class = Userend
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#74?email_source=notifications&email_token=AAAATKDDDXQMIMSWAV5LWITQO6LCNA5CNFSM4JBGVRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBOFSIY#issuecomment-542923043>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAATKHO5KHMBU7LPB4X3A3QO6LCNANCNFSM4JBGVRUA>
.
|
What if the default behavior is to create a class (current behavior), unless one with the appropriate naming convention already exists? In that case the naming convention might even be overkill, and using the |
@zacharyw so instead of falling back to a generic context class with no validations and no attribute methods you're suggesting the fallback would be the current behavior? |
@aaronmallen I think so. I do see the benefit of being able to set a custom context, but for a lot of simple base case scenarios it may be annoying to have to manually keep creating new classes. |
Problem
Currently when a class inherits from
ActiveInteractor::Base
a context class is created and validation and attribute methods are delegated from the interactor to the context class. I wonder if this method of delegation is too "magic" or too confusing.Proposal
I propose a new pattern for handling context. I would like to expect a context class be created in addition to the interactor class with a given naming convention. For example given an interactor named
MyInteractor
the gem could expect a second classMyInteractorContext
to exist and if it cannot find that class it would fallback to a generic context class with no validation or attribute methods. The expectation would be instead of going the route of delegation through the interactor with methods likecontext_validates
all validation and attribute methods would be called on the context class directly. The generators in the gem could make this easy when developing with rails.so instead of the current pattern:
the pattern could be:
The goal here is to provide clarity on where these validations occur.
Things to consider before answering
MyInteractor::Context
is what is created)?The text was updated successfully, but these errors were encountered: