Sha256: 9a02168311f21ca34a4bce66f951418150dac2a1d270824b967beca234d4db67

Contents?: true

Size: 1.28 KB

Versions: 22

Compression:

Stored size: 1.28 KB

Contents

module CurationConcerns
  class PresenterFactory
    class << self
      # @param [Array] ids the list of ids to load
      # @param [Class] klass the class of presenter to make
      # @return [Array] presenters for the generic files in order of the ids
      def build_presenters(ids, klass, ability)
        new(ids, klass, ability).build
      end
    end

    attr_reader :ids, :klass, :ability

    def initialize(ids, klass, ability)
      @ids = ids
      @klass = klass
      @ability = ability
    end

    def build
      return [] if ids.blank?
      docs = load_docs
      ids.map do |id|
        solr_doc = docs.find { |doc| doc.id == id }
        klass.new(solr_doc, ability) if solr_doc
      end.compact
    end

    private

      # @return [Array<SolrDocument>] a list of solr documents in no particular order
      def load_docs
        query("{!terms f=id}#{ids.join(',')}", rows: 1000)
          .map { |res| SolrDocument.new(res) }
      end

      # Query solr using POST so that the query doesn't get too large for a URI
      def query(query, args = {})
        args[:q] = query
        args[:qt] = 'standard'
        conn = ActiveFedora::SolrService.instance.conn
        result = conn.post('select', data: args)
        result.fetch('response').fetch('docs')
      end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
curation_concerns-0.14.0.pre3 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.14.0.pre2 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.14.0.pre1 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.13.1 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.13.0 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre9 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre8 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre7 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre6 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre5 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre4 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre3 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre2 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.12.0.pre1 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.11.0 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.11.0.rc1 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.10.0 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.9.0 app/presenters/curation_concerns/presenter_factory.rb
curation_concerns-0.8.0 app/presenters/curation_concerns/presenter_factory.rb