module Blacklight

Constants

VERSION

Public Class Methods

blacklight_config_file() click to toggle source
# File lib/blacklight.rb, line 13
def self.blacklight_config_file
  Rails.root.join("config/blacklight.yml")
end
blacklight_yml() click to toggle source
# File lib/blacklight.rb, line 65
def self.blacklight_yml
  require 'erb'
  require 'yaml'

  return @blacklight_yml if @blacklight_yml
  unless blacklight_yml?
    raise "You are missing a configuration file: #{blacklight_config_file}. Have you run \"rails generate blacklight:install\"?"
  end

  begin
    blacklight_erb = ERB.new(File.read(blacklight_config_file)).result(binding)
  rescue StandardError, SyntaxError => e
    raise("#{blacklight_config_file} was found, but could not be parsed with ERB. \n#{e.inspect}")
  end

  begin
    @blacklight_yml = if RUBY_VERSION > '2.6'
                        YAML.safe_load(blacklight_erb, aliases: true)
                      else
                        YAML.safe_load(blacklight_erb, [], [], true)
                      end
  rescue => e
    raise("#{blacklight_config_file} was found, but could not be parsed.\n#{e.inspect}")
  end

  if @blacklight_yml.nil? || !@blacklight_yml.is_a?(Hash)
    raise("#{blacklight_config_file} was found, but was blank or malformed.\n")
  end

  @blacklight_yml
end
blacklight_yml?() click to toggle source
# File lib/blacklight.rb, line 97
def self.blacklight_yml?
  File.exist?(blacklight_config_file)
end
connection_config() click to toggle source
# File lib/blacklight.rb, line 50
def self.connection_config
  Blacklight::RuntimeRegistry.connection_config ||= blacklight_yml[::Rails.env]&.symbolize_keys if blacklight_yml?
end
connection_config=(value) click to toggle source
# File lib/blacklight.rb, line 54
def self.connection_config=(value)
  Blacklight::RuntimeRegistry.connection_config = value
end
default_configuration() click to toggle source

The default Blacklight configuration.

# File lib/blacklight.rb, line 46
def self.default_configuration
  Blacklight::Configuration.new
end
default_index() click to toggle source

The default index connection for the search index

# File lib/blacklight.rb, line 19
def self.default_index
  Blacklight::RuntimeRegistry.connection ||= repository_class.new(default_configuration)
end
default_index=(repository) click to toggle source
# File lib/blacklight.rb, line 23
def self.default_index=(repository)
  Blacklight::RuntimeRegistry.connection = repository
end
deprecation() click to toggle source
# File lib/blacklight.rb, line 122
def self.deprecation
  @deprecation ||= ActiveSupport::Deprecation.new('9.0', 'Blacklight')
end
logger() click to toggle source
# File lib/blacklight.rb, line 101
def self.logger
  @logger ||= (::Rails.logger if defined? Rails && Rails.respond_to?(:logger))
end
logger=(logger) click to toggle source
# File lib/blacklight.rb, line 105
def self.logger= logger
  @logger = logger
end
repository_class() click to toggle source

The configured repository class. By convention, this is the class Blacklight::(name of the adapter)::Repository, e.g.

elastic_search => Blacklight::ElasticSearch::Repository
# File lib/blacklight.rb, line 31
def self.repository_class
  case connection_config[:adapter]
  when 'solr'
    Blacklight::Solr::Repository
  when /::/
    connection_config[:adapter].constantize
  else
    raise "The value for :adapter was not found in the blacklight.yml config" unless connection_config.key? :adapter

    Blacklight.const_get("#{connection_config.fetch(:adapter)}/Repository".classify)
  end
end
root() click to toggle source

returns the full path the the blacklight plugin installation

# File lib/blacklight.rb, line 118
def self.root
  @root ||= File.expand_path(File.dirname(File.dirname(__FILE__)))
end
version() click to toggle source
# File lib/blacklight/version.rb, line 5
def self.version
  @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
end

Public Instance Methods

defaults_version() click to toggle source
# File lib/blacklight.rb, line 58
def defaults_version
  @defaults_version ||= blacklight_yml['load_defaults'] ||
                        Blacklight::VERSION

  @defaults_version == 'latest' ? Blacklight::VERSION : @defaults_version
end