collections.rb 1.0 KB

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