Sha256: 97c012092845d099fcde40fc39de6d65716d2a1a01ceb78c3583b3be23fb8034

Contents?: true

Size: 1023 Bytes

Versions: 6

Compression:

Stored size: 1023 Bytes

Contents

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

    before_validation do
      if document && document.uploaded_resource?
        self.image = document.uploaded_resource.url.file
      end
    end

    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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blacklight-spotlight-0.8.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.7.2 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.7.1 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.7.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.6.0 app/models/spotlight/featured_image.rb
blacklight-spotlight-0.5.0 app/models/spotlight/featured_image.rb