Skip to content

Commit

Permalink
Merge pull request #3010 from projectblacklight/class-as-keyword
Browse files Browse the repository at this point in the history
Pass the class argument to serialize as a keyword
  • Loading branch information
taylor-steve committed Jul 2, 2024
2 parents 87c47de + 3f1489f commit 9ed6da6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
30 changes: 21 additions & 9 deletions app/models/spotlight/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ class BlacklightConfiguration < ActiveRecord::Base
has_paper_trail

belongs_to :exhibit, touch: true, optional: true
serialize :facet_fields, Hash, coder: YAML
serialize :index_fields, Hash, coder: YAML
serialize :search_fields, Hash, coder: YAML
serialize :sort_fields, Hash, coder: YAML
serialize :default_solr_params, Hash, coder: YAML
serialize :show, Hash, coder: YAML
serialize :index, Hash, coder: YAML
serialize :per_page, Array, coder: YAML
serialize :document_index_view_types, Array, coder: YAML
if Rails.version > '7.1'
serialize :facet_fields, type: Hash, coder: YAML
serialize :index_fields, type: Hash, coder: YAML
serialize :search_fields, type: Hash, coder: YAML
serialize :sort_fields, type: Hash, coder: YAML
serialize :default_solr_params, type: Hash, coder: YAML
serialize :show, type: Hash, coder: YAML
serialize :index, type: Hash, coder: YAML
serialize :per_page, type: Array, coder: YAML
serialize :document_index_view_types, type: Array, coder: YAML
else
serialize :facet_fields, Hash, coder: YAML
serialize :index_fields, Hash, coder: YAML
serialize :search_fields, Hash, coder: YAML
serialize :sort_fields, Hash, coder: YAML
serialize :default_solr_params, Hash, coder: YAML
serialize :show, Hash, coder: YAML
serialize :index, Hash, coder: YAML
serialize :per_page, Array, coder: YAML
serialize :document_index_view_types, Array, coder: YAML
end

include Spotlight::BlacklightConfigurationDefaults

Expand Down
7 changes: 5 additions & 2 deletions app/models/spotlight/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class Contact < ActiveRecord::Base
belongs_to :exhibit, touch: true, optional: true
scope :published, -> { where(show_in_sidebar: true) }
default_scope { order('weight ASC') }
serialize :contact_info, Hash, coder: YAML

if Rails.version > '7.1'
serialize :contact_info, type: Hash, coder: YAML
else
serialize :contact_info, Hash, coder: YAML
end
extend FriendlyId
friendly_id :name, use: %i[slugged scoped finders], scope: :exhibit

Expand Down
6 changes: 5 additions & 1 deletion app/models/spotlight/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module Spotlight
##
# Exhibit custom fields
class CustomField < ActiveRecord::Base
serialize :configuration, Hash, coder: YAML
if Rails.version > '7.1'
serialize :configuration, type: Hash, coder: YAML
else
serialize :configuration, Hash, coder: YAML
end
belongs_to :exhibit, optional: true

extend FriendlyId
Expand Down
6 changes: 5 additions & 1 deletion app/models/spotlight/custom_search_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
module Spotlight
# Exhibit-specific custom search fields
class CustomSearchField < ApplicationRecord
serialize :configuration, Hash, coder: YAML
if Rails.version > '7.1'
serialize :configuration, type: Hash, coder: YAML
else
serialize :configuration, Hash, coder: YAML
end
belongs_to :exhibit

def label=(label)
Expand Down
7 changes: 5 additions & 2 deletions app/models/spotlight/exhibit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ class Exhibit < ActiveRecord::Base
acts_as_tagger
acts_as_taggable
delegate :blacklight_config, to: :blacklight_configuration
serialize :facets, Array, coder: YAML

if Rails.version > '7.1'
serialize :facets, type: Array, coder: YAML
else
serialize :facets, Array, coder: YAML
end
# NOTE: friendly id associations need to be 'destroy'ed to reap the slug history
has_many :about_pages, -> { for_default_locale }, extend: FriendlyId::FinderMethods
has_many :attachments, dependent: :destroy
Expand Down
6 changes: 5 additions & 1 deletion app/models/spotlight/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class Resource < ActiveRecord::Base
has_many :solr_document_sidecars
has_many :events, as: :resource

serialize :data, Hash, coder: YAML
if Rails.version > '7.1'
serialize :data, type: Hash, coder: YAML
else
serialize :data, Hash, coder: YAML
end

##
# Persist the record to the database, and trigger a reindex to solr
Expand Down
10 changes: 7 additions & 3 deletions app/models/spotlight/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ class Search < ActiveRecord::Base
has_many :groups, through: :group_memberships
accepts_nested_attributes_for :group_memberships
accepts_nested_attributes_for :groups
if defined?(Blacklight::SearchParamsYamlCoder)
serialize :query_params, Blacklight::SearchParamsYamlCoder, default: -> { {} }
if defined?(Blacklight::SearchParamsYamlCoder) # in Blacklight 7.28.0+
serialize :query_params, coder: Blacklight::SearchParamsYamlCoder, default: -> { {} }
else
serialize :query_params, Hash
if Rails.version > '7.1' # rubocop:disable Style/IfInsideElse
serialize :query_params, type: Hash
else
serialize :query_params, Hash
end
end
default_scope { order('weight ASC') }
scope :published, -> { where(published: true) }
Expand Down
10 changes: 8 additions & 2 deletions app/models/spotlight/solr_document_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ class SolrDocumentSidecar < ActiveRecord::Base
belongs_to :exhibit, optional: false
belongs_to :resource, optional: true
belongs_to :document, optional: false, polymorphic: true
serialize :data, Hash, coder: YAML
serialize :index_status, Hash, coder: YAML

if Rails.version > '7.1'
serialize :data, type: Hash, coder: YAML
serialize :index_status, type: Hash, coder: YAML
else
serialize :data, Hash, coder: YAML
serialize :index_status, Hash, coder: YAML
end

delegate :has_key?, :key?, to: :data

Expand Down

0 comments on commit 9ed6da6

Please sign in to comment.