Forked from jodosha/create_email_test_operation.rb
Last active
August 29, 2015 14:13
-
-
Save andreapavoni/5b69202813c5948fd190 to your computer and use it in GitHub Desktop.
This file contains 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment