Module: Spotlight::Etl::Transforms

Defined in:
app/services/spotlight/etl/transforms.rb

Overview

Basic + default transform steps

Constant Summary collapse

IdentityTransform =

A transform step that “transforms” the source into the data element

lambda do |data, pipeline|
  data.merge(pipeline.source)
end
RejectBlank =

A transform step that throws away blank data

lambda do |data, _|
  throw :skip if data.blank?
  data
end
RejectMissingUniqueId =

A trasnform step that ensures data has a unique key attribute

lambda do |data, pipeline|
  id = pipeline.context.unique_key(data)

  throw :skip if id.blank?
  data
end
ApplyExhibitMetadata =

A transform that adds exhibit-specific metadata (like Spotlight sidecar data) to the document

lambda do |data, pipeline|
  resource = pipeline.context.resource
  document_model = pipeline.context.document_model
  id = pipeline.context.unique_key(data)

  next data unless document_model && id.present?

   = document_model.build_for_exhibit(id, resource.exhibit, resource: (resource if resource.persisted?))

  data.reverse_merge(.to_solr)
end
ApplyApplicationMetadata =

A transform that adds application-specific metadata (like what resource generated the solr document)

lambda do |data, pipeline|
  resource = pipeline.context.resource
  document_model = pipeline.context.document_model

  data.reverse_merge(
    Spotlight::Engine.config.resource_global_id_field => (resource.to_global_id.to_s if resource.persisted?),
    document_model.resource_type_field => resource.class.to_s.tableize
  )
end
ApplyPipelineMetadata =

A transform that adds externally-provided metadata to the document

lambda do |data, pipeline|
  data.reverse_merge(pipeline.context.)
end

Class Method Summary collapse

Class Method Details

.SourceMethodTransform(method) ⇒ Object

A transform step that calls a method on the source to generate a document



13
14
15
16
17
# File 'app/services/spotlight/etl/transforms.rb', line 13

def self.SourceMethodTransform(method) # rubocop:disable Naming/MethodName
  lambda do |data, pipeline|
    data.merge(pipeline.source.public_send(method))
  end
end