Class: Hyrax::CustomQueries::Navigators::CollectionMembers

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/navigators/collection_members.rb

Overview

Find members of collections and collections for members

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ CollectionMembers

Returns a new instance of CollectionMembers.

Since:

  • 3.0.0



22
23
24
# File 'app/services/hyrax/custom_queries/navigators/collection_members.rb', line 22

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Since:

  • 3.0.0



20
21
22
# File 'app/services/hyrax/custom_queries/navigators/collection_members.rb', line 20

def query_service
  @query_service
end

Class Method Details

.queriesArray<Symbol>

Returns Array<Symbol>.

Returns:

  • (Array<Symbol>)

    Array<Symbol>

Since:

  • 3.0.0



14
15
16
# File 'app/services/hyrax/custom_queries/navigators/collection_members.rb', line 14

def self.queries
  [:find_collections_for, :find_members_of]
end

Instance Method Details

#find_collections_for(resource:) ⇒ Array<Valkyrie::Resource>

Find child works of a given resource, and map to Valkyrie Resources

Parameters:

  • resource (Valkyrie::Resource)

Returns:

  • (Array<Valkyrie::Resource>)

Since:

  • 3.0.0



31
32
33
34
# File 'app/services/hyrax/custom_queries/navigators/collection_members.rb', line 31

def find_collections_for(resource:)
  query_service
    .find_references_by(resource: resource, property: :member_of_collection_ids)
end

#find_members_of(collection:) ⇒ Array<Valkyrie::Resource>

Find members for the given collection

Parameters:

  • collection (Valkyrie::Resource)

Returns:

  • (Array<Valkyrie::Resource>)

Since:

  • 3.0.0



41
42
43
44
# File 'app/services/hyrax/custom_queries/navigators/collection_members.rb', line 41

def find_members_of(collection:)
  query_service
    .find_inverse_references_by(resource: collection, property: :member_of_collection_ids)
end