Class: Hyrax::CustomQueries::FindIdsByModel

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindIdsByModel

Returns a new instance of FindIdsByModel.


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

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service


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

def query_service
  @query_service
end

Class Method Details

.queriesObject


7
8
9
# File 'app/services/hyrax/custom_queries/find_ids_by_model.rb', line 7

def self.queries
  [:find_ids_by_model]
end

Instance Method Details

#find_ids_by_model(model:, ids: :all) ⇒ Enumerable<Valkyrie::ID>

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:

  • model (Class)
  • ids (Enumerable<#to_s>, Symbol) (defaults to: :all)

Returns:

  • (Enumerable<Valkyrie::ID>)

28
29
30
31
32
33
34
# File 'app/services/hyrax/custom_queries/find_ids_by_model.rb', line 28

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