Skip to content

Commit

Permalink
Encapsulate the blacklight config
Browse files Browse the repository at this point in the history
All values set on Blacklight::Engine.config are actually stored
in a class variable on Railtie::Configuration. So these pollute
that namespace.  All other railties are encapsulating their configs
onto a single entry in that scope.  This change makes Blacklight do
likewise.

This probably needs to be a major revision
  • Loading branch information
jcoyne committed Mar 7, 2019
1 parent 037633c commit 4b9855f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Blacklight::Bookmarks
before_action :verify_user

blacklight_config.track_search_session = false
blacklight_config.http_method = Blacklight::Engine.config.bookmarks_http_method
blacklight_config.http_method = Blacklight::Engine.config.blacklight.bookmarks_http_method
blacklight_config.add_results_collection_tool(:clear_bookmarks_widget)

blacklight_config.show.document_actions[:bookmark].if = false if blacklight_config.show.document_actions[:bookmark]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ def validate_sms_params
end

def sms_mappings
Blacklight::Engine.config.sms_mappings
Blacklight::Engine.config.blacklight.sms_mappings
end

def validate_email_params
if params[:to].blank?
flash[:error] = I18n.t('blacklight.email.errors.to.blank')
elsif !params[:to].match(Blacklight::Engine.config.email_regexp)
elsif !params[:to].match(Blacklight::Engine.config.blacklight.email_regexp)
flash[:error] = I18n.t('blacklight.email.errors.to.invalid', to: params[:to])
end

Expand Down
13 changes: 10 additions & 3 deletions lib/blacklight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class Engine < Rails::Engine
end
end

Blacklight::Engine.config.sms_mappings = {
bl_global_config = OpenStruct.new

bl_global_config.sms_mappings = {
'Virgin' => 'vmobl.com',
'AT&T' => 'txt.att.net',
'Verizon' => 'vtext.com',
Expand All @@ -42,9 +44,14 @@ class Engine < Rails::Engine
'Cricket' => 'mms.mycricket.com'
}

config.bookmarks_http_method = :post
bl_global_config.bookmarks_http_method = :post

bl_global_config.email_regexp = defined?(Devise) ? Devise.email_regexp : /\A[^@\s]+@[^@\s]+\z/

config.email_regexp = defined?(Devise) ? Devise.email_regexp : /\A[^@\s]+@[^@\s]+\z/
# Anything that goes into Blacklight::Engine.config is stored as a class
# variable on Railtie::Configuration. we're going to encapsulate all the
# Blacklight specific stuff in this single struct:
Blacklight::Engine.config.blacklight = bl_global_config

config.action_dispatch.rescue_responses.merge!(
"Blacklight::Exceptions::RecordNotFound" => :not_found
Expand Down

0 comments on commit 4b9855f

Please sign in to comment.