Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate the blacklight config #2083

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -257,13 +257,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 @@ -30,7 +30,9 @@ class Engine < Rails::Engine
end
end

Blacklight::Engine.config.sms_mappings = {
bl_global_config = OpenStructWithHashAccess.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
'Google Fi' => 'msg.fi.google.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["Blacklight::Exceptions::RecordNotFound"] = :not_found

Expand Down