Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class DoThing
  2. include Dry::Transaction
  3.  
  4. Context = Struct.new(:user, :params, :accumulator)
  5. Result = Struct.new(:output)
  6. Error = Struct.new(:step, :errors)
  7.  
  8. step :build_context
  9. step :operation_one
  10. step :operation_two
  11. failure :recover_one
  12. step :operation_three
  13. step :operation_four
  14. failure :recover_two
  15. step :prepare_result
  16.  
  17. private
  18.  
  19. def build_context(input)
  20. Success(Context.new(input[:user], input[:params], {}))
  21. end
  22.  
  23. def prepare_result(context)
  24. Success(Result.new(context.accumulator[:output]))
  25. end
  26.  
  27. def operation_one(context)
  28. # ...
  29. end
  30.  
  31. def operation_two(context)
  32. # ...
  33. end
  34.  
  35. def operation_three(context)
  36. # ...
  37. end
  38.  
  39. def operation_four(context)
  40. # ...
  41. end
  42.  
  43. def recover_one(error)
  44. # Success() with some recovery
  45. end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement