Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement