Class: SolrDocumentSidecar

Inherits:
GeoblacklightSidecarImages::ApplicationRecord show all
Defined in:
app/models/solr_document_sidecar.rb

Overview

ActiveRecord sidecar for a Solr document, with an attached thumbnail image.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.transition_classObject



33
34
35
# File 'app/models/solr_document_sidecar.rb', line 33

def self.transition_class
  SidecarImageTransition
end

Instance Method Details

#documentObject

SolrDocument is not an ActiveRecord model. Reconstruct from the stored id.



18
19
20
# File 'app/models/solr_document_sidecar.rb', line 18

def document
  document_type.new document_type.unique_key => document_id
end

#document_typeObject



22
23
24
# File 'app/models/solr_document_sidecar.rb', line 22

def document_type
  (super.constantize if defined?(super)) || default_document_type
end

#image_stateObject



26
27
28
29
30
31
# File 'app/models/solr_document_sidecar.rb', line 26

def image_state
  @image_state ||= SidecarImageStateMachine.new(
    self,
    transition_class: SidecarImageTransition
  )
end

#image_urlObject



41
42
43
44
45
# File 'app/models/solr_document_sidecar.rb', line 41

def image_url
  return unless image.attached?

  Rails.application.routes.url_helpers.rails_blob_path(image, only_path: true)
end

#reimage!Object



47
48
49
50
# File 'app/models/solr_document_sidecar.rb', line 47

def reimage!
  image.purge if image.attached?
  GeoblacklightSidecarImages::StoreImageJob.perform_later(document.id)
end