Class: Wings::CustomQueries::FindManyByAlternateIds

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/services/custom_queries/find_many_by_alternate_ids.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindManyByAlternateIds

Returns a new instance of FindManyByAlternateIds.



16
17
18
# File 'lib/wings/services/custom_queries/find_many_by_alternate_ids.rb', line 16

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service.



13
14
15
# File 'lib/wings/services/custom_queries/find_many_by_alternate_ids.rb', line 13

def query_service
  @query_service
end

Class Method Details

.queriesObject

Custom query override specific to Wings Use:

Hyrax.custom_queries.find_many_by_alternate_ids(alternate_ids: ids, use_valkyrie: true)


9
10
11
# File 'lib/wings/services/custom_queries/find_many_by_alternate_ids.rb', line 9

def self.queries
  [:find_many_by_alternate_ids]
end

Instance Method Details

#find_many_by_alternate_ids(alternate_ids:, use_valkyrie: true) ⇒ Array<Valkyrie::Resource>, Array<ActiveFedora::Base>

implements a combination of two Valkyrie queries:

> find_many_by_ids & find_by_alternate_identifier

Parameters:

  • alternate_ids (Enumerator<#to_s>)

    list of ids

  • use_valkyrie (boolean) (defaults to: true)

    defaults to true; optionally return ActiveFedora::Base objects if false

Returns:



25
26
27
28
29
30
31
32
# File 'lib/wings/services/custom_queries/find_many_by_alternate_ids.rb', line 25

def find_many_by_alternate_ids(alternate_ids:, use_valkyrie: true)
  af_objects = ActiveFedora::Base.find(alternate_ids.map(&:to_s))
  return af_objects unless use_valkyrie == true

  af_objects.map do |af_object|
    resource_factory.to_resource(object: af_object)
  end
end