Module: Hyrax::ValkyrieLazyMigration

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/hyrax/valkyrie_lazy_migration.rb

Overview

This mixin is for Valkyrie::Resource objects to be able to read/write the same Solr document as their corresponding ActiveFedora::Base object.

Defined Under Namespace

Classes: ResourceName

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.migrating(klass, from:, name_class: Hyrax::ValkyrieLazyMigration::ResourceName) ⇒ Object

Note:

This is similar to the Wings::ModelRegistry.register, but is envisioned as part of

This function helps configuration a work for a valkyrie migration; namely by helping re-use an existing SOLR document, by specifying that the given :klass is a migration :from another class.

the Frigg and Freyja adapters for Postges and Fedora lazy migrations.

Examples:

class MyWork < ActiveFedora::Base
end

class MyWorkResource < Hyrax::Resource
  Hyrax::ValkyrieLazyMigration.migrating(self, from: MyWork)
end

Parameters:

  • klass (Hyrax::Resource, .attribute)
  • from (ActiveFedora::Base, .to_rdf_representation)
  • name_class (Hyrax::Name) (defaults to: Hyrax::ValkyrieLazyMigration::ResourceName)

    responsible, in part, for determining the various routing paths you might use.



52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/hyrax/valkyrie_lazy_migration.rb', line 52

def self.migrating(klass, from:, name_class: Hyrax::ValkyrieLazyMigration::ResourceName)
  Wings::ModelRegistry.register(klass, from)
  from.singleton_class.define_method(:migrating_from) { from }
  from.singleton_class.define_method(:migrating_to) { klass }
  klass.singleton_class.define_method(:migrating_from) { from }
  klass.singleton_class.define_method(:migrating_to) { klass }
  klass.singleton_class.define_method(:_hyrax_default_name_class) { name_class }
  klass.singleton_class.define_method(:to_rdf_representation) { migrating_from.to_rdf_representation }

  klass.include(self)
end

Instance Method Details

#membersObject



70
71
72
73
74
75
76
77
# File 'app/models/concerns/hyrax/valkyrie_lazy_migration.rb', line 70

def members
  return @members if @members.present?
  @members = member_ids.map do |id|
    Hyrax.query_service.find_by(id: id)
  rescue Valkyrie::Persistence::ObjectNotFoundError
    Rails.logger.warn("Could not find member #{id} for #{self.id}")
  end
end

#to_solrObject



79
80
81
# File 'app/models/concerns/hyrax/valkyrie_lazy_migration.rb', line 79

def to_solr
  Hyrax::ValkyrieIndexer.for(resource: self).to_solr
end