Last active
July 12, 2019 02:12
-
-
Save siassaj/d6ed898578628e09386143f806960543 to your computer and use it in GitHub Desktop.
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 DoThing | |
include Dry::Transaction | |
Context = Struct.new(:user, :params, :accumulator) | |
Result = Struct.new(:output) | |
Error = Struct.new(:step, :errors) | |
step :build_context | |
step :operation_one | |
step :operation_two | |
failure :recover_one | |
step :operation_three | |
step :operation_four | |
failure :recover_two | |
step :prepare_result | |
private | |
def build_context(input) | |
Success(Context.new(input[:user], input[:params], {})) | |
end | |
def prepare_result(context) | |
Success(Result.new(context.accumulator[:output])) | |
end | |
def operation_one(context) | |
# ... | |
end | |
def operation_two(context) | |
# ... | |
end | |
def operation_three(context) | |
# ... | |
end | |
def operation_four(context) | |
# ... | |
end | |
def recover_one(error) | |
# Success() with some recovery | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment