1
0

canonical_email_block.rb 927 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: canonical_email_blocks
  5. #
  6. # id :bigint(8) not null, primary key
  7. # canonical_email_hash :string default(""), not null
  8. # reference_account_id :bigint(8)
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. #
  12. class CanonicalEmailBlock < ApplicationRecord
  13. include EmailHelper
  14. include Paginable
  15. belongs_to :reference_account, class_name: 'Account', optional: true
  16. validates :canonical_email_hash, presence: true, uniqueness: true
  17. scope :matching_email, ->(email) { where(canonical_email_hash: email_to_canonical_email_hash(email)) }
  18. def to_log_human_identifier
  19. canonical_email_hash
  20. end
  21. def email=(email)
  22. self.canonical_email_hash = email_to_canonical_email_hash(email)
  23. end
  24. def self.block?(email)
  25. matching_email(email).exists?
  26. end
  27. end