lib/sanitize_email/config.rb in sanitize_email-2.0.0 vs lib/sanitize_email/config.rb in sanitize_email-2.0.1
- old
+ new
@@ -1,13 +1,14 @@
+# frozen_string_literal: true
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
# Released under the MIT license
module SanitizeEmail
# The API for configuring SanitizeEmail is via `SanitizeEmail.config`
# Available configuration options are listed in the `DEFAULTS` constant.
class Config
-
extend SanitizeEmail::Deprecation
class << self
attr_accessor :config
end
@@ -32,13 +33,13 @@
# a black list
:bad_list => nil,
:environment => if defined?(Rails) && Rails.env.present?
- ("[" << Rails.env << "]")
+ "[#{Rails.env}]"
else
- "[UNKNOWN ENVIRONMENT]"
+ '[UNKNOWN ENVIRONMENT]'
end,
# Use the "real" email address as the username
# for the sanitized email address
# e.g. "real@example.com <sanitized@example.com>"
@@ -54,41 +55,48 @@
# True / False turns on or off sanitization,
# while nil ignores this setting and checks activation_proc
:engage => nil,
- :activation_proc => Proc.new { false }
- }
+ :activation_proc => proc { false },
+ }.freeze
@config ||= DEFAULTS.dup
- def self.configure &block
+ def self.configure
yield @config
# Gracefully handle deprecated config values.
# Actual deprecation warnings are thrown in the top SanitizeEmail module
# thanks to our use of dynamic methods.
if @config[:local_environments] && defined?(Rails)
- @config[:activation_proc] = Proc.new {
+ @config[:activation_proc] = proc do
SanitizeEmail.local_environments.include?(Rails.env)
- }
+ end
end
if @config[:sanitized_recipients]
# calling it to trigger the deprecation warning.
# Won't actually be set with any value,
# because we are still inside the configure block.
SanitizeEmail.sanitized_recipients
@config[:sanitized_to] = @config[:sanitized_recipients]
end
- if !@config[:force_sanitize].nil?
- deprecation_warning_message(
- <<-EOS
+ config_force_sanitize_deprecation_warning
+ end
+
+ def self.config_force_sanitize_deprecation_warning
+ return nil if @config[:force_sanitize].nil?
+ deprecation_warning_message(
+ <<-DEPRECATION
SanitizeEmail::Config.config[:force_sanitize] is deprecated.
Please use SanitizeEmail.force_sanitize or SanitizeEmail.sanitary instead.
Refer to https://github.com/pboling/sanitize_email/wiki for examples.
- EOS
- )
- SanitizeEmail.force_sanitize = @config[:force_sanitize]
- end
+ DEPRECATION
+ )
+ SanitizeEmail.force_sanitize = @config[:force_sanitize]
end
+ INIT_KEYS = [:sanitized_to, :sanitized_cc, :sanitized_bcc, :good_list, :bad_list].freeze
+ def self.to_init
+ @config.select { |key, _value| INIT_KEYS.include?(key) }
+ end
end
end