Sha256: dae583dc733bc32bedeccd0cb2b85aa13bb605c22555886e4e93018d1491aaba

Contents?: true

Size: 1.11 KB

Versions: 47

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
module Valkyrie::Persistence::Solr
  # Composite object to make multiple custom indexers act like a single one, so
  # that upstream code doesn't have to know how to iterate over indexers.
  #
  # @see https://en.wikipedia.org/wiki/Composite_pattern
  class CompositeIndexer
    attr_reader :indexers

    # @param [Array<Object>] indexers
    def initialize(*indexers)
      @indexers = indexers
    end

    # Construct a new Instance object
    # @param [Valkyrie::Resource] resource
    def new(resource:)
      Instance.new(indexers, resource: resource)
    end

    # Class providing the common method interface for the Indexer
    class Instance
      attr_reader :indexers, :resource

      # @param [Array<Object>] indexers
      # @param [Valkyrie::Resource] resource
      def initialize(indexers, resource:)
        @resource = resource
        @indexers = indexers.map { |i| i.new(resource: resource) }
      end

      # Generate the Solr Documents from the indexers
      # @return [Array<Hash>]
      def to_solr
        indexers.map(&:to_solr).inject({}, &:merge)
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
valkyrie-2.1.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC10 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC9 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.7.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC8 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.7.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC7 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC6 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC5 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC4 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.6.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.5.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC3 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.5.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.5.0.RC2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-1.5.0.RC1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.0.0.RC1 lib/valkyrie/persistence/solr/composite_indexer.rb