Sha256: c319925507f0e27c6da7761ef254884ca2ed05a2aa44c2ce25b1c64a20623006

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Hyrax
  module CustomQueries
    module Navigators
      ##
      # Find members of collections and collections for members
      #
      # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
      # @since 3.0.0
      class CollectionMembers
        ##
        # @return [Array<Symbol>
        def self.queries
          [:find_collections_for, :find_members_of]
        end
        ##
        # @!attribute [r] query_service
        #   @return [#custom_queries]
        attr_reader :query_service

        def initialize(query_service:)
          @query_service = query_service
        end

        ##
        # Find child works of a given resource, and map to Valkyrie Resources
        #
        # @param [Valkyrie::Resource] resource
        # @return [Array<Valkyrie::Resource>]
        def find_collections_for(resource:)
          query_service
            .find_references_by(resource: resource, property: :member_of_collection_ids)
        end

        ##
        # Find members for the given collection
        #
        # @param [Valkyrie::Resource] collection
        # @return [Array<Valkyrie::Resource>]
        def find_members_of(collection:)
          query_service
            .find_inverse_references_by(resource: collection, property: :member_of_collection_ids)
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

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