Sha256: 930ac1e75e49a5471fb7f553bbcb5b09d9236084c878b829ae22804b8aee66d7

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module Spotlight::BlacklightConfigurationDefaults
  extend ActiveSupport::Concern

  included do
    before_create :setup_defaults
  end


  protected
    def setup_defaults
      default_sort_fields
      default_view_types
      set_default_per_page
    end

    def default_sort_fields
      return true unless sort_fields.empty?

      # can't use default_blacklight_config until after the BlacklightConfiguration
      # is created or we run into a circular dependency.
      default_fields = ::CatalogController.blacklight_config.sort_fields
      self.sort_fields = default_fields.each_with_object({}) do |(k, v), obj|
        obj[k] = { show: true }
      end
    end

    def default_view_types
      return true unless document_index_view_types.empty?

      # can't use default_blacklight_config until after the BlacklightConfiguration
      # is created or we run into a circular dependency.
      self.document_index_view_types = ::CatalogController.blacklight_config.view.keys.map(&:to_s)
    end

    def set_default_per_page
      # can't use default_blacklight_config until after the BlacklightConfiguration
      # is created or we run into a circular dependency.
      self.default_per_page ||= ::CatalogController.blacklight_config.per_page.first
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-spotlight-0.2.0 app/models/concerns/spotlight/blacklight_configuration_defaults.rb