-
-
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
[RFC] A more DSL friendly approach #229
Comments
To address the issue of maintaining class SocialMediaInteractor < ActiveInteractor::Base
perform :tweet do
puts "Tweeting..."
result = Twitter::Client.send(context.message)
state.fail!(result.body) if result.status != :ok
end
rollback :tweet do
...
end
perform :facebook do
puts "Posting to Facebook..."
result = Facebook::Client.send(context.message)
state.fail!(result.body) if result.status != :ok
end
rollback :facebook do
...
end
end |
What benefits does this DSL provide over the current PORO design? Personally, the reason I like something like Pundit vs cancancan is that it's simple and extensible; you don't have to work around the DSL. It's also easy to substitute something else during tests, whereas if each of your interactors follows a different interface (tweet, facebook, etc.) then you can't just stub something out that plays a generic "interactor" role, you have to care about the specific interactor you plug in. I also think the If there are use cases you're thinking of that the DSL makes simpler or easier to understand, then that might change things. But the way I see it, this change only adds a slight layer of abstraction for little benefit, and in fact some drawbacks. |
In your DSL the SocialMediaInteractor is encouraging mixing environments with differing implantation and promotes mixing the different implementations for FB and Twitter, et.al. into a monolithic class. IMO this encourages developers to include every possible social media task into the same class structure which I fear will just result in yet another 800 line class to scroll through (or to include) to find or use a single interaction point. Where as the current DSL promotes sparse separation of function and purpose. Each network has its own separation of functions and may still be included in a more monolithic class or dsl wrapper for your application needs, but the developer is guided to separate concerns from the start. I like the DSL concept perhaps as a seperate grouping construct, but not as the default implementation. This would make a good gem. But a poor core addition IMO. |
I tend to agree with the comments here and am closing this as resolved. |
For version 2.0 I'd like to make activeinteractor a little more DSL friendly:
On the current version of activeinteractor (1.0.4) you can do something like this:
I'd like developers to instead be able to do something more akin to this:
Additionally it should be noted status reporting has been abstracted into a new object called
state
to reduce the responsibility of thecontext
object.The underlying benefit is developers would now be able to either invoke all
perform
methods on a given interactor (i.e.SocialMediaInteractor.perform(...)
) or specific methods (i.e.SocialMediaInteractor.tweet(...)
) and still have the value of attribute validation and callbacks.The text was updated successfully, but these errors were encountered: