Class: Spotlight::FeaturedImage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spotlight/featured_image.rb

Overview

Featured images for browse categories, feature pages, and exhibits

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#upload_idObject

Returns the value of attribute upload_id.



36
37
38
# File 'app/models/spotlight/featured_image.rb', line 36

def upload_id
  @upload_id
end

Instance Method Details

#documentObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/spotlight/featured_image.rb', line 51

def document
  return unless document_global_id && source == 'exhibit'

  @document = nil if @document && document_global_id != @document.to_global_id.to_s

  @document ||= GlobalID::Locator.locate document_global_id
rescue Blacklight::Exceptions::RecordNotFound => e
  Rails.logger.info("Exception fetching record by id: #{document_global_id}")
  Rails.logger.info(e)

  nil
end

#file_present?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/spotlight/featured_image.rb', line 64

def file_present?
  image.file.present?
end

#iiif_tilesourceObject



68
69
70
71
72
73
74
75
# File 'app/models/spotlight/featured_image.rb', line 68

def iiif_tilesource
  if self[:iiif_tilesource]
    self[:iiif_tilesource]
  elsif file_present?
    riiif = Riiif::Engine.routes.url_helpers
    riiif.info_path(self)
  end
end

#iiif_urlObject



38
39
40
41
42
# File 'app/models/spotlight/featured_image.rb', line 38

def iiif_url
  return unless iiif_service_base.present?

  [iiif_service_base, iiif_region || 'full', image_size.join(','), '0', 'default.jpg'].join('/')
end

#remote_image_url=(url) ⇒ Object

This is used to fetch images given the URL field in the CSV uploads If the image is local, this step will fail, which is okay since the only consumer is CSV uploads and the URL is intended to be remote



47
48
49
# File 'app/models/spotlight/featured_image.rb', line 47

def remote_image_url=(url)
  super url unless url.starts_with? '/'
end

#to_paramObject

Include a hashed updated_at timestamp in the parameter key to bust any browser caching.



79
80
81
# File 'app/models/spotlight/featured_image.rb', line 79

def to_param
  "#{id}-#{Digest::MD5.hexdigest(updated_at.iso8601)}"
end