Sha256: d372274bd9f3ee0f25b907d4147a64b213ec9fb90e7ee7525a70e025fe1fb026

Contents?: true

Size: 1.7 KB

Versions: 21

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Blacklight::Configurable
  extend ActiveSupport::Concern

  included do
    helper_method :blacklight_config if respond_to? :helper_method
  end

  # instance methods for blacklight_config, so get a deep copy of the class-level config
  def blacklight_config
    @blacklight_config ||= self.class.blacklight_config.deep_copy
  end
  attr_writer :blacklight_config

  class_methods do
    def copy_blacklight_config_from(other_class)
      self.blacklight_config = other_class.blacklight_config.inheritable_copy(self)
    end

    # lazy load a deep_copy of superclass if present, else
    # a default_configuration, which will be legacy load or new empty config.
    # note the @blacklight_config variable is a ruby 'instance method on class
    # object' that won't be automatically available to subclasses, that's why
    # we lazy load to 'inherit' how we want.
    def blacklight_config
      @blacklight_config ||= if superclass.respond_to?(:blacklight_config)
                               superclass.blacklight_config.build(self)
                             else
                               default_configuration
                             end
    end
    attr_writer :blacklight_config

    # simply a convenience method for blacklight_config.configure
    def configure_blacklight(...)
      blacklight_config.configure(...)
    end

    ##
    # The default configuration object
    def default_configuration
      Blacklight::Configurable.default_configuration.inheritable_copy(self)
    end
  end

  def self.default_configuration
    @default_configuration ||= Blacklight::Configuration.new
  end

  def self.default_configuration= config
    @default_configuration = config
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/models/concerns/blacklight/configurable.rb
blacklight-8.6.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.5.1 app/models/concerns/blacklight/configurable.rb
blacklight-8.5.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.4.0 app/models/concerns/blacklight/configurable.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/models/concerns/blacklight/configurable.rb
blacklight-8.3.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.2.2 app/models/concerns/blacklight/configurable.rb
blacklight-8.2.1 app/models/concerns/blacklight/configurable.rb
blacklight-8.2.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.1.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.1 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta8 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta7 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta6 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta5 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta4 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta3 app/models/concerns/blacklight/configurable.rb
blacklight-8.0.0.beta2 app/models/concerns/blacklight/configurable.rb