Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreapavoni/5b69202813c5948fd190 to your computer and use it in GitHub Desktop.
Save andreapavoni/5b69202813c5948fd190 to your computer and use it in GitHub Desktop.
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
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