Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. # solution provided by Eloy Duran
  2.  
  3. class API
  4. def self.get(id)
  5. new(with_response_data)
  6. end
  7. end
  8.  
  9. class APIWithIdentityMap < API
  10. def self.map
  11. Thread.current[:map][self] ||= {}
  12. end
  13.  
  14. def self.get(id)
  15. map[id] ||= super
  16. end
  17. end
  18.  
  19. def session
  20. Thread.current[:map] = {}
  21. yield
  22. ensure
  23. Thread.current[:map] = nil
  24. end
  25.  
  26. session do
  27. # logic that performs requests
  28. end
Add Comment
Please, Sign In to add comment