collections.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. class Sessions::Backend::Collections < Sessions::Backend::Base
  2. def initialize(user, asset_lookup, client, client_id, ttl = 10)
  3. @user = user
  4. @client = client
  5. @client_id = client_id
  6. @ttl = ttl
  7. @asset_lookup = asset_lookup
  8. @backends = backend
  9. @time_now = Time.zone.now.to_i
  10. end
  11. def push
  12. results = []
  13. @backends.each do |backend|
  14. #puts "B: #{backend.inspect}"
  15. result = backend.push
  16. #puts "R: #{result.inspect}"
  17. if result
  18. results.push result
  19. end
  20. end
  21. results
  22. end
  23. def user=(user)
  24. @user = user
  25. # update stored user in backends, too
  26. @backends.each do |backend|
  27. backend.user = user
  28. end
  29. end
  30. def backend
  31. # auto population collections
  32. backends = []
  33. # load collections to deliver from external files
  34. dir = File.expand_path('../../..', __dir__)
  35. files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb")
  36. files.each do |file|
  37. file.gsub!("#{dir}/lib/", '')
  38. file.gsub!(/\.rb$/, '')
  39. next if file.classify == 'Sessions::Backend::Collections::Base'
  40. #puts "LOAD #{file.classify}---"
  41. #next if file == ''
  42. backend = file.classify.constantize.new(@user, @asset_lookup, @client, @client_id, @ttl)
  43. if backend
  44. backends.push backend
  45. end
  46. end
  47. backends
  48. end
  49. end