class Sessions::Backend::Collections < Sessions::Backend::Base

  def initialize(user, asset_lookup, client, client_id, ttl = 10)
    @user         = user
    @client       = client
    @client_id    = client_id
    @ttl          = ttl
    @asset_lookup = asset_lookup
    @backends     = backend
  end

  def push
    results = []
    @backends.each { |backend|
      #puts "B: #{backend.inspect}"
      result = backend.push
      #puts "R: #{result.inspect}"
      if result
        results.push result
      end
    }
    results
  end

  def backend

    # auto population collections
    backends = []

    # load collections to deliver from external files
    dir = File.expand_path('../../../../', __FILE__)
    files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb")
    files.each { |file|
      file.gsub!("#{dir}/lib/", '')
      file.gsub!(/\.rb$/, '')
      next if file.classify == 'Sessions::Backend::Collections::Base'
      #puts "LOAD #{file.classify}---"
      #next if file == ''
      backend = file.classify.constantize.new(@user, @asset_lookup, @client, @client_id, @ttl)
      if backend
        backends.push backend
      end
    }

    backends
  end

end
