Sha256: 76d55194d5e5a90c9206dd2c11bffa4e449cfe818a0d1de5565a304eef117b2a

Contents?: true

Size: 1.13 KB

Versions: 23

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
module Hyrax
  module CustomQueries
    ##
    # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
    class FindIdsByModel
      def self.queries
        [:find_ids_by_model]
      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 model [Class]
      # @param ids [Enumerable<#to_s>, Symbol]
      #
      # @return [Enumerable<Valkyrie::ID>]
      def find_ids_by_model(model:, ids: :all)
        return query_service.find_all_of_model(model: model).map(&:id) if ids == :all

        query_service.find_many_by_ids(ids: ids).select do |resource|
          resource.is_a?(model)
        end.map(&:id)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-5.0.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-5.0.0.rc3 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-5.0.0.rc2 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-5.0.0.rc1 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.6.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0.rc3 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0.rc2 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0.rc1 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.5.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0.beta2 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.4.2 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-4.0.0.beta1 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.4.1 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.4.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.3.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.2.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.1.0 app/services/hyrax/custom_queries/find_ids_by_model.rb
hyrax-3.0.2 app/services/hyrax/custom_queries/find_ids_by_model.rb