From 276332c58dda5f8a3c6961fc8ee3a66e6a7a2489 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Sun, 10 Nov 2024 04:46:30 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20Prefer=20require=20relative=20(#?= =?UTF-8?q?123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ Prefer require_relative > require for internal refs within {lib,spec} - `require_relative` is preferred over `require` for files within the same project because it uses paths relative to the current file, making code more portable and less dependent on the load path. This change updates internal requires to use `require_relative` for consistency, performance, and improved portability. Ref: - rubocop/rubocop#8748 * 📝 Fix documentation formatting * 🔖 Prepare release v2.0.10 --- .rubocop_gradual.lock | 2 +- CHANGELOG.md | 13 ++++++++++++- Gemfile.lock | 2 +- README.md | 29 ++++++++++++++-------------- lib/sanitize_email.rb | 18 ++++++++--------- lib/sanitize_email/rspec_matchers.rb | 2 +- lib/sanitize_email/version.rb | 2 +- spec/config/rspec/helpers.rb | 2 +- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 12 ++++++------ 10 files changed, 47 insertions(+), 37 deletions(-) diff --git a/.rubocop_gradual.lock b/.rubocop_gradual.lock index c6765bf..7cf297d 100644 --- a/.rubocop_gradual.lock +++ b/.rubocop_gradual.lock @@ -2,7 +2,7 @@ "init.rb:3429808413": [ [3, 9, 16, "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.", 29970817] ], - "lib/sanitize_email.rb:1609191393": [ + "lib/sanitize_email.rb:1050465130": [ [57, 5, 29, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 1399760671] ], "lib/sanitize_email/config.rb:393256477": [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be4329..3aee09e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Removed +## [2.0.10] - 2024-11-09 ([tag][2.0.10t]) +- COVERAGE: 90.15% -- 247/274 lines in 8 files +- BRANCH COVERAGE: 71.68% -- 81/113 branches in 8 files +- 61.73% documented +### Fixed +* Prefer `require_relative` > `require` internally + * Better performance, portability, and consistency + * See: https://github.com/rubocop/rubocop/issues/8748 + ## [2.0.9] - 2024-11-09 ([tag][2.0.9t]) - COVERAGE: 90.15% -- 247/274 lines in 8 files - BRANCH COVERAGE: 71.68% -- 81/113 branches in 8 files @@ -311,7 +320,9 @@ Old version? * Fixed require paths * added about.yml and this CHANGELOG -[Unreleased]: https://github.com/pboling/sanitize_email/compare/v2.0.9...HEAD +[Unreleased]: https://github.com/pboling/sanitize_email/compare/v2.0.10...HEAD +[2.0.10]: https://github.com/pboling/sanitize_email/compare/v2.0.9...v2.0.10 +[2.0.10t]: https://github.com/pboling/sanitize_email/tags/v2.0.10 [2.0.9]: https://github.com/pboling/sanitize_email/compare/v2.0.8...v2.0.9 [2.0.9t]: https://github.com/pboling/sanitize_email/tags/v2.0.9 [2.0.8]: https://github.com/pboling/sanitize_email/compare/v2.0.7...v2.0.8 diff --git a/Gemfile.lock b/Gemfile.lock index 733283a..ee89995 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sanitize_email (2.0.9) + sanitize_email (2.0.10) mail (~> 2.0) version_gem (~> 1.1, >= 1.1.4) diff --git a/README.md b/README.md index 706d3f0..815110d 100644 --- a/README.md +++ b/README.md @@ -375,8 +375,7 @@ Regardless of the Config settings of SanitizeEmail you can do a local override t You have access to all the same configuration options in the parameter hash as you can set in the actual `SanitizeEmail.configure` block. - - SanitizeEmail.sanitary({sanitized_to: "boo@example.com"}) do # these config options are merged with the globals + SanitizeEmail.sanitary(sanitized_to: "boo@example.com") do # these config options are merged with the globals Mail.deliver do from "from@example.org" to "to@example.org" # Will actually be sent to the override addresses, in this case: boo@example.com @@ -390,19 +389,19 @@ You have access to all the same configuration options in the parameter hash as y As used in the "Description" column below, `engaged` means: `SanitizeEmail.activate?(message) # => true`. This happens in a few different ways, and two of them are in the config below (`engage` and `activation_proc`). -| Option | Type (Yard format) | Description | -|---------------------------------------------|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| -| sanitized_to | [String, Array[String]] | (when engaged) Override CC field with these addresses | -| sanitized_cc | [String, Array[String]] | (when engaged) Override CC field with these addresses | -| sanitized_bcc | [String, Array[String]] | (when engaged) Override BCC field with these addresses | -| good_list | [Array[String]] | (when engaged) Email addresses to allow to pass-through without overriding | -| bad_list | [Array[String]] | (when engaged) Email addresses to be removed from message's TO, CC, & BCC | -| environment | [String, #to_s, Proc, Lambda, #call] | (when engaged) The environment value to use wherever it is added to message (e.g. in the subject line) | -| use_actual_email_as_sanitized_user_name | [Boolean] | (when engaged) Use "real" email address as username for sanitized email address (e.g. "real at example.com ") | -| use_actual_email_prepended_to_subject | [Boolean] | (when engaged) Use "real" email address prepended to subject (e.g. "real at example.com Original Subject") | -| use_actual_environment_prepended_to_subject | [Boolean] | (when engaged) Use `environment` prepended to subject (e.g. "{{ STAGING }} Original Subject") | -| engage | [Boolean, nil] | Boolean will turn engage or disengage this gem, while `nil` ignores this setting and instead checks `activation_proc` | -| activation_proc | [Proc, Lambda, #call] | When checked, due to `engage: nil`, the result will either engage or disengage this gem | +| Option | Type (Yard format) | Description | +|---------------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| +| sanitized_to | [String, Array[String]] | (when engaged) Override CC field with these addresses | +| sanitized_cc | [String, Array[String]] | (when engaged) Override CC field with these addresses | +| sanitized_bcc | [String, Array[String]] | (when engaged) Override BCC field with these addresses | +| good_list | [Array[String]] | (when engaged) Email addresses to allow to pass-through without overriding | +| bad_list | [Array[String]] | (when engaged) Email addresses to be removed from message's TO, CC, & BCC | +| environment | [String, #to_s, Proc, Lambda, #call] | (when engaged) The environment value to use wherever it is added to message (e.g. in the subject line) | +| use_actual_email_as_sanitized_user_name | [Boolean] | (when engaged) Use "real" email address as username for sanitized email address (e.g. `"real at example.com "`) | +| use_actual_email_prepended_to_subject | [Boolean] | (when engaged) Use "real" email address prepended to subject (e.g. `"real at example.com Original Subject"`) | +| use_actual_environment_prepended_to_subject | [Boolean] | (when engaged) Use `environment` prepended to subject (e.g. `"[[ STAGING ]] Original Subject"`) | +| engage | [Boolean, nil] | Boolean will turn engage or disengage this gem, while `nil` ignores this setting and instead checks `activation_proc` | +| activation_proc | [Proc, Lambda, #call] | When checked, due to `engage: nil`, the result will either engage or disengage this gem | ## Thread Safety diff --git a/lib/sanitize_email.rb b/lib/sanitize_email.rb index 9500354..125efb2 100644 --- a/lib/sanitize_email.rb +++ b/lib/sanitize_email.rb @@ -7,12 +7,12 @@ require "version_gem" # This Library -require "sanitize_email/version" -require "sanitize_email/deprecation" -require "sanitize_email/config" -require "sanitize_email/mail_header_tools" -require "sanitize_email/overridden_addresses" -require "sanitize_email/bleach" +require_relative "sanitize_email/version" +require_relative "sanitize_email/deprecation" +require_relative "sanitize_email/config" +require_relative "sanitize_email/mail_header_tools" +require_relative "sanitize_email/overridden_addresses" +require_relative "sanitize_email/bleach" module SanitizeEmail # Error is raised when a block parameter is required and not provided to a method @@ -26,13 +26,13 @@ class MissingBlockParameter < StandardError; end if defined?(::Rails::Engine) if ::Rails::VERSION::MAJOR >= 6 # Rails 6.0+ - require "sanitize_email/engine_v6" + require_relative "sanitize_email/engine_v6" else # Rails 3.1 to 5.2 - require "sanitize_email/engine_v5" + require_relative "sanitize_email/engine_v5" end elsif ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR.zero? - require "sanitize_email/railtie" + require_relative "sanitize_email/railtie" else raise "Please use the 0.X.X versions of sanitize_email for Rails 2.X and below." end diff --git a/lib/sanitize_email/rspec_matchers.rb b/lib/sanitize_email/rspec_matchers.rb index 2405c4b..66c4cec 100644 --- a/lib/sanitize_email/rspec_matchers.rb +++ b/lib/sanitize_email/rspec_matchers.rb @@ -5,7 +5,7 @@ # Note: the RspecMatchers are composed matchers: # See: http://www.relishapp.com/rspec/rspec-expectations/v/3-5/docs/composing-matchers -require "sanitize_email/mail_ext" +require_relative "mail_ext" module SanitizeEmail # Provides matchers that can be used in diff --git a/lib/sanitize_email/version.rb b/lib/sanitize_email/version.rb index cc93613..77175db 100644 --- a/lib/sanitize_email/version.rb +++ b/lib/sanitize_email/version.rb @@ -5,6 +5,6 @@ module SanitizeEmail module Version - VERSION = "2.0.9" + VERSION = "2.0.10" end end diff --git a/spec/config/rspec/helpers.rb b/spec/config/rspec/helpers.rb index fc8d70d..932c323 100644 --- a/spec/config/rspec/helpers.rb +++ b/spec/config/rspec/helpers.rb @@ -1,4 +1,4 @@ -require "support/sanitizer_spec_helpers" +require_relative "../../support/sanitizer_spec_helpers" RSpec.configure do |config| config.include SanitizerSpecHelpers diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 198dd63..e021f8b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" ENV["RAILS_ENV"] ||= "test" # Last thing before loading this gem is to setup code coverage diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6b4c5b7..9327c07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,9 +6,9 @@ require "rspec/pending_for" # RSpec Configs -require "config/byebug" -require "config/rspec/helpers" -require "config/rspec/rspec_block_is_expected" -require "config/rspec/rspec_core" -require "config/rspec/version_gem" -require "support/matchers" +require_relative "config/byebug" +require_relative "config/rspec/helpers" +require_relative "config/rspec/rspec_block_is_expected" +require_relative "config/rspec/rspec_core" +require_relative "config/rspec/version_gem" +require_relative "support/matchers"