Skip to content

Commit

Permalink
Use a PerThreadRegistry for the Blacklight connection and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 15, 2016
1 parent 653b83e commit 2d376e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Blacklight
autoload :Exceptions, 'blacklight/exceptions'
autoload :Parameters, 'blacklight/parameters'
autoload :Routes, 'blacklight/routes'
autoload :RuntimeRegistry, 'blacklight/runtime_registry'
autoload :SearchBuilder, 'blacklight/search_builder'
autoload :SearchState, 'blacklight/search_state'
autoload :Solr, 'blacklight/solr'
Expand All @@ -26,7 +27,11 @@ def self.blacklight_config_file
##
# The default index connection for the search index
def self.default_index
repository_class.new(default_configuration)
Blacklight::RuntimeRegistry.connection ||= repository_class.new(default_configuration)
end

def self.default_index=(repository)
Blacklight::RuntimeRegistry.connection = repository
end

##
Expand All @@ -52,10 +57,14 @@ def self.default_configuration
end

def self.connection_config
@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
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

def self.connection_config=(value)
Blacklight::RuntimeRegistry.connection_config = value
end

def self.blacklight_yml
Expand Down
9 changes: 9 additions & 0 deletions lib/blacklight/runtime_registry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'active_support/per_thread_registry'

module Blacklight
class RuntimeRegistry
extend ActiveSupport::PerThreadRegistry

attr_accessor :connection, :connection_config
end
end

0 comments on commit 2d376e8

Please sign in to comment.