spacepaste

  1.  
  2. class Assignment
  3. def transfer(person_id: nil, attempt: 0)
  4. random = false
  5. if !person_id
  6. person_id = get_random_person.id
  7. random = true
  8. end
  9. @thing.update(assignee: person_id)
  10. rescue NotFound
  11. raise 'Person not found' if !random
  12. attempt += 1
  13. raise if attempt > 3
  14. new_person = get_random_person(refresh: true)
  15. transfer(
  16. person_id: new_person.id,
  17. attempt: attempt
  18. )
  19. end
  20. private
  21. def get_random_person(refresh: false)
  22. @person = nil if refresh
  23. @person ||= begin
  24. RandomPerson.new
  25. end
  26. end
  27. end
  28.