collections.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. end
  10. def push
  11. results = []
  12. @backends.each { |backend|
  13. #puts "B: #{backend.inspect}"
  14. result = backend.push
  15. #puts "R: #{result.inspect}"
  16. if result
  17. results.push result
  18. end
  19. }
  20. results
  21. end
  22. def backend
  23. # auto population collections
  24. backends = []
  25. # load collections to deliver from external files
  26. dir = File.expand_path('../../../../', __FILE__)
  27. files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb")
  28. files.each { |file|
  29. file.gsub!("#{dir}/lib/", '')
  30. file.gsub!(/\.rb$/, '')
  31. next if file.classify == 'Sessions::Backend::Collections::Base'
  32. #puts "LOAD #{file.classify}---"
  33. #next if file == ''
  34. backend = file.classify.constantize.new(@user, @asset_lookup, @client, @client_id, @ttl)
  35. if backend
  36. backends.push backend
  37. end
  38. }
  39. backends
  40. end
  41. end