Sha256: 93a16e797d87551c52dc9381cfa66a3385e0129e468942820a3bffbf5b95be89

Contents?: true

Size: 1.25 KB

Versions: 21

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
module Hyrax
  module CustomQueries
    # @example
    #   collection_type = Hyrax::CollectionType.find(1)
    #
    #   Hyrax.custom_queries.find_collections_by_type(global_id: Hyrax::GlobalID(collection_type))
    #
    # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
    class FindCollectionsByType
      def self.queries
        [:find_collections_by_type]
      end

      def initialize(query_service:)
        @query_service = query_service
      end

      attr_reader :query_service
      delegate :resource_factory, to: :query_service

      ##
      # @note this is an unoptimized default implementation of this custom
      #   query. it's Hyrax's policy to provide such implementations of custom
      #   queries in use for cross-compatibility of Valkyrie query services.
      #   it's advisable to provide an optimized query for the specific adapter.
      #
      # @param global_id [GlobalID] global id for a Hyrax::CollectionType
      #
      # @return [Enumerable<PcdmCollection>]
      def find_collections_by_type(global_id:)
        query_service
          .find_all_of_model(model: PcdmCollection)
          .select { |collection| collection.collection_type_gid == global_id }
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-5.0.0.rc1 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.6.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0.rc3 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0.rc2 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0.rc1 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.5.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0.beta2 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.4.2 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-4.0.0.beta1 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.4.1 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.4.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.3.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.2.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.1.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.0.2 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.0.1 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.0.0 app/services/hyrax/custom_queries/find_collections_by_type.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/custom_queries/find_collections_by_type.rb