Class: Hyrax::CustomQueries::FindCollectionsByType

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

Overview

Examples:

collection_type = Hyrax::CollectionType.find(1)

Hyrax.custom_queries.find_collections_by_type(global_id: Hyrax::GlobalID(collection_type))

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindCollectionsByType

Returns a new instance of FindCollectionsByType.



15
16
17
# File 'app/services/hyrax/custom_queries/find_collections_by_type.rb', line 15

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service.



19
20
21
# File 'app/services/hyrax/custom_queries/find_collections_by_type.rb', line 19

def query_service
  @query_service
end

Class Method Details

.queriesObject



11
12
13
# File 'app/services/hyrax/custom_queries/find_collections_by_type.rb', line 11

def self.queries
  [:find_collections_by_type]
end

Instance Method Details

#find_collections_by_type(global_id:) ⇒ Enumerable<PcdmCollection>

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.

Parameters:

  • global_id (GlobalID)

    global id for a Hyrax::CollectionType

Returns:



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

def find_collections_by_type(global_id:)
  query_service
    .find_all_of_model(model: Hyrax.config.collection_model.safe_constantize)
    .select { |collection| collection.collection_type_gid == global_id }
end