Last active
October 2, 2016 01:06
-
-
Save jodosha/f8b11f22e431cffc43e4 to your computer and use it in GitHub Desktop.
Interactors proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateEmailTest | |
include Lotus::Interactor | |
def initialize(params) | |
@params = params | |
@email_test = EmailTest.new(@params[:email_test]) | |
end | |
def call | |
Operation.new(self, email_test: @email_test). | |
then(:validate). | |
then(:persist). | |
then(:capture_screenshot). | |
then(:deliver_emails).run | |
end | |
private | |
def validate | |
errors @params.errors unless @params.valid? | |
end | |
def persist | |
EmailTestRepository.create(@email_test) | |
end | |
def capture_screenshot | |
Screenshot.new(@email_test).capture | |
rescue | |
error "There was a problem while capturing the screenshot" | |
end | |
def deliver_emails | |
# ... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateEmailTest | |
include Lotus::Interactor | |
def initialize(params) | |
@params = params | |
@email_test = EmailTest.new(@params[:email_test]) | |
end | |
# List the operations to execute. | |
# Once error/errors is called, it uses `throw` to interrupt the flow. | |
# | |
# It has an implicit return value: | |
# Result | |
# email_test (how to declare its inclusion?) | |
# errors | |
# success? | |
def call | |
validate | |
persist | |
capture_screenshot | |
deliver_emails | |
end | |
private | |
def validate | |
errors @params.errors unless @params.valid? | |
end | |
def persist | |
@email_test = EmailTestRepository.create(@email_test) | |
error "Not persisted" if @email_test.id.nil? | |
end | |
def capture_screenshot | |
Screenshot.new(@email_test).capture | |
rescue | |
error "There was a problem while capturing the screenshot" | |
end | |
def deliver_emails | |
# ... | |
end | |
end |
The Interactors module will be included under apps or under lib? I mean, the use cases layer is going to be specific to each app or will it be an abstraction on top of domain model?
I'm asking this because in the clean architecture recommended by Uncle Bob, those interactors are part of the core of the business domain workflow while I think different apps will have different use cases.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So you're naming it
Operation
after Trailblazer? Or where does theOperation
class come from?