module Blacklight

Constants

VERSION

Public Class Methods

blacklight_config_file() click to toggle source
# File lib/blacklight.rb, line 24
def self.blacklight_config_file
  "#{::Rails.root}/config/blacklight.yml"
end
blacklight_yml() click to toggle source
# File lib/blacklight.rb, line 83
def self.blacklight_yml
  require 'erb'
  require 'yaml'

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

  begin
    blacklight_erb = ERB.new(IO.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
connection_config() click to toggle source
# File lib/blacklight.rb, line 61
def self.connection_config
  Blacklight::RuntimeRegistry.connection_config ||= begin
    raise "The #{::Rails.env} environment settings were not found in the blacklight.yml config" unless blacklight_yml[::Rails.env]

    blacklight_yml[::Rails.env].symbolize_keys
  end
end
connection_config=(value) click to toggle source
# File lib/blacklight.rb, line 69
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 57
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 30
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 34
def self.default_index=(repository)
  Blacklight::RuntimeRegistry.connection = repository
end
logger() click to toggle source
# File lib/blacklight.rb, line 115
def self.logger
  @logger ||= begin
    ::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
  end
end
logger=(logger) click to toggle source
# File lib/blacklight.rb, line 121
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 42
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 134
def self.root
  @root ||= File.expand_path(File.dirname(File.dirname(__FILE__)))
end
version() click to toggle source
# File lib/blacklight/version.rb, line 4
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 73
def defaults_version
  @defaults_version ||= blacklight_yml['load_defaults'] ||
                        # this config parameter was introduced in Blacklight 7.11, so to be safe,
                        # we pin any 7.x app to the 7.10 behavior
                        (Blacklight::VERSION.starts_with?('7') && '7.10.0') ||
                        Blacklight::VERSION

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