Skip to content

Commit

Permalink
🔀 Prefer require relative (#123)
Browse files Browse the repository at this point in the history
* ♻️ 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
  • Loading branch information
pboling authored Nov 9, 2024
1 parent 4a68d74 commit 276332c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .rubocop_gradual.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <sanitized@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 <sanitized@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

Expand Down
18 changes: 9 additions & 9 deletions lib/sanitize_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sanitize_email/rspec_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sanitize_email/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

module SanitizeEmail
module Version
VERSION = "2.0.9"
VERSION = "2.0.10"
end
end
2 changes: 1 addition & 1 deletion spec/config/rspec/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "support/sanitizer_spec_helpers"
require_relative "../../support/sanitizer_spec_helpers"

RSpec.configure do |config|
config.include SanitizerSpecHelpers
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 276332c

Please sign in to comment.