Sha256: 298264bcb979da474921f7906e91d8e9162bd613e6d407ba8eb20f49d29d4ce9

Contents?: true

Size: 1.25 KB

Versions: 45

Compression:

Stored size: 1.25 KB

Contents

module Spotlight
  ##
  # Featured images for browse categories, feature pages, and exhibits
  class FeaturedImage < ActiveRecord::Base
    mount_uploader :image, Spotlight::FeaturedImageUploader

    before_validation :set_image_from_uploaded_resource

    after_save do
      if image.present?
        image.cache! unless image.cached?
        image.store!
        recreate_image_versions
      end
    end

    def remote_image_url=(url)
      # if the image is local, this step will fail..
      # hopefully it's local because it's an uploaded resource, and we'll
      # catch is in before_validation..
      super url unless url.starts_with? '/'
    end

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

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

      @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

    private

    def set_image_from_uploaded_resource
      return unless document && document.uploaded_resource?
      self.image = document.uploaded_resource.url.file
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
blacklight-spotlight-0.32.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.31.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.30.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.29.1 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.29.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.28.3 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.28.2 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.28.1 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.28.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.27.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.26.1 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.26.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.25.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.24.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.23.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.22.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.21.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.20.3 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.20.2 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.20.1 app/models/spotlight/featured_image.rb