Skip to content

Commit

Permalink
Use blacklight.yml rather than solr.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 12, 2015
1 parent 7ec430d commit bcf532e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
59 changes: 52 additions & 7 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding : utf-8 -*-
require 'kaminari'
require 'rsolr'
require 'deprecation'
module Blacklight

autoload :Configurable, 'blacklight/configurable'
Expand Down Expand Up @@ -33,7 +34,8 @@ module Blacklight
autoload :Facet, 'blacklight/facet'

extend SearchFields

extend Deprecation

require 'blacklight/version'
require 'blacklight/engine' if defined?(Rails)

Expand All @@ -45,24 +47,67 @@ class << self
# other services (e.g. refworks callback urls)
mattr_accessor :secret_key
@@secret_key = nil


# @deprecated
def self.solr_file
"#{::Rails.root.to_s}/config/solr.yml"
end


def self.blacklight_config_file
"#{::Rails.root.to_s}/config/blacklight.yml"
end

def self.add_routes(router, options = {})
Blacklight::Routes.new(router, options).draw
end

def self.solr
@solr ||= RSolr.connect(Blacklight.solr_config)
@solr ||= RSolr.connect(Blacklight.connection_config)
end

def self.solr_config
@solr_config ||= begin
raise "The #{::Rails.env} environment settings were not found in the solr.yml config" unless solr_yml[::Rails.env]
solr_yml[::Rails.env].symbolize_keys
Deprecation.warn Blacklight, "Blacklight.solr_config is deprecated and will be removed in 6.0.0. Use Blacklight.connection_config instead", caller
connection_config
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
end

def self.blacklight_yml
require 'erb'
require 'yaml'

return @blacklight_yml if @blacklight_yml
unless File.exists?(blacklight_config_file)
if File.exists?(solr_file)
Deprecation.warn Blacklight, "Configuration is now done via blacklight.yml. Suppport for solr.yml will be removed in blacklight 6.0.0"
return solr_yml
else
raise "You are missing a solr configuration file: #{solr_file}. Have you run \"rails generate blacklight:install\"?"
end
end

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

begin
@blacklight_yml = YAML::load(blacklight_erb)
rescue StandardError => e
raise("#{blacklight_config_file} was found, but could not be parsed.\n")
end

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

return @blacklight_yml
end

def self.solr_yml
Expand Down
3 changes: 3 additions & 0 deletions lib/blacklight/abstract_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def connection


protected
def connection_config
@connection_config ||= Blacklight.connection_config
end

def logger
@logger ||= Rails.logger if defined? Rails
Expand Down
6 changes: 3 additions & 3 deletions lib/blacklight/solr_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def blacklight_solr=(conn)
end
deprecation_deprecate :blacklight_solr=


def blacklight_solr_config
@blacklight_solr_config ||= Blacklight.solr_config
connection_config
end
deprecation_deprecate :blacklight_solr_config

protected

def build_connection
RSolr.connect(blacklight_solr_config)
RSolr.connect(connection_config)
end
end
end
4 changes: 2 additions & 2 deletions lib/generators/blacklight/models_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ModelsGenerator < Rails::Generators::Base
desc """
This generator makes the following changes to your application:
1. Creates several database migrations if they do not exist in /db/migrate
2. Creates config/solr.yml with a default solr configuration
2. Creates config/blacklight.yml with a default configuration
3. Injects behavior into your user model
4. Creates a blacklight document in your /app/models directory
"""
Expand Down Expand Up @@ -54,7 +54,7 @@ def generate_devise_assets

# Copy all files in templates/config directory to host config
def create_configuration_files
copy_file "config/solr.yml", "config/solr.yml"
copy_file "config/blacklight.yml", "config/blacklight.yml"
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
# how to start up solr, generally for automated testing.

development:
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/blacklight-core" %>
test: &test
adapter: solr
url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8888}/solr/blacklight-core" %>
production:
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/blacklight-core" %>
4 changes: 2 additions & 2 deletions lib/generators/blacklight/test_support_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class TestSupport < Rails::Generators::Base
good with default blacklight setup, including solr conf files for out
of the box blacklight.
Also adds jetty_path key to solr.yml for selected environment, to refer
to this install.
Also adds jetty_path key to blacklight.yml for selected environment, to refer
to this install.
"""
def alternate_controller
copy_file "alternate_controller.rb", "app/controllers/alternate_controller.rb"
Expand Down

5 comments on commit bcf532e

@atz
Copy link
Member

@atz atz commented on bcf532e Mar 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generators don't really do what their docs say anymore. I don't see test_support_generator adding jetty_path key to anything. And the JETTY_PATH notes in blacklight.yml should be in jetty.yml.

@jcoyne
Copy link
Member Author

@jcoyne jcoyne commented on bcf532e Mar 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is jetty_path needed anymore? Where is it used?

@atz
Copy link
Member

@atz atz commented on bcf532e Mar 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In jetty.yml.

@jcoyne
Copy link
Member Author

@jcoyne jcoyne commented on bcf532e Mar 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atz I see it there, but what's the purpose of it being there?

@atz
Copy link
Member

@atz atz commented on bcf532e Mar 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hell if I know.

Please sign in to comment.