diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb deleted file mode 100644 index 0800601f98b..00000000000 --- a/app/helpers/email_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module EmailHelper - def self.included(base) - base.extend(self) - end - - def email_to_canonical_email(str) - username, domain = str.downcase.split('@', 2) - username, = username.delete('.').split('+', 2) - - "#{username}@#{domain}" - end - - def email_to_canonical_email_hash(str) - Digest::SHA2.new(256).hexdigest(email_to_canonical_email(str)) - end -end diff --git a/app/models/canonical_email_block.rb b/app/models/canonical_email_block.rb index d09df6f5e2a..19e9d6bbf76 100644 --- a/app/models/canonical_email_block.rb +++ b/app/models/canonical_email_block.rb @@ -12,7 +12,7 @@ # class CanonicalEmailBlock < ApplicationRecord - include EmailHelper + include CanonicalEmail include Paginable belongs_to :reference_account, class_name: 'Account', optional: true @@ -26,7 +26,7 @@ class CanonicalEmailBlock < ApplicationRecord end def email=(email) - self.canonical_email_hash = email_to_canonical_email_hash(email) + self.canonical_email_hash = self.class.email_to_canonical_email_hash(email) end def self.block?(email) diff --git a/app/models/concerns/canonical_email.rb b/app/models/concerns/canonical_email.rb new file mode 100644 index 00000000000..7dae59e52f6 --- /dev/null +++ b/app/models/concerns/canonical_email.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module CanonicalEmail + extend ActiveSupport::Concern + + class_methods do + def email_to_canonical_email_hash(value) + Digest::SHA2 + .new(256) + .hexdigest( + email_to_canonical_email(value) + ) + end + + private + + def email_to_canonical_email(value) + username, domain = value.downcase.split('@', 2) + username, = username.delete('.').split('+', 2) + + "#{username}@#{domain}" + end + end +end