app/models/spotlight/exhibit.rb in blacklight-spotlight-3.0.0.alpha.2 vs app/models/spotlight/exhibit.rb in blacklight-spotlight-3.0.0.alpha.3
- old
+ new
@@ -3,10 +3,11 @@
require 'mail'
module Spotlight
##
# Spotlight exhibit
class Exhibit < ActiveRecord::Base
+ class_attribute :themes_selector
include Spotlight::ExhibitAnalytics
include Spotlight::ExhibitDefaults
include Spotlight::ExhibitDocuments
include Spotlight::Translatables
@@ -19,11 +20,11 @@
scope :ordered_by_weight, -> { order('weight ASC') }
paginates_per 48
extend FriendlyId
- friendly_id :title, use: [:slugged, :finders]
+ friendly_id :title, use: %i[slugged finders]
validates :title, presence: true, if: -> { I18n.locale == I18n.default_locale }
validates :slug, uniqueness: true
validates :theme, inclusion: { in: Spotlight::Engine.config.exhibit_themes }, allow_blank: true
acts_as_tagger
@@ -84,10 +85,18 @@
def browse_categories?
searches.published.any?
end
+ def themes
+ @themes ||= begin
+ return Spotlight::Engine.config.exhibit_themes unless self.class.themes_selector
+
+ self.class.themes_selector.call(self)
+ end
+ end
+
def to_s
title
end
def import(hash)
@@ -112,10 +121,10 @@
def searchable?
blacklight_config.search_fields.any? { |_k, v| v.enabled && v.include_in_simple_select != false }
end
def requested_by
- roles.first.user if roles.first
+ roles.first&.user
end
def reindex_progress
@reindex_progress ||= ReindexProgress.new(current_reindexing_log_entry)
end