Skip to content

Commit

Permalink
feat(ruby): add add_custom_domains
Browse files Browse the repository at this point in the history
  • Loading branch information
choznerol committed Nov 9, 2021
1 parent 72b47aa commit 167cad2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions platform/ruby/mail_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def self.blacklisted?(email)
extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
end

def self.add_custom_domains(domains)
domains.each do |domain|
BLACKLIST.add(domain)
end
end

def self.extract_all_domain_suffixes(email)
domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase

Expand Down
6 changes: 6 additions & 0 deletions platform/ruby/mail_checker.tmpl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def self.blacklisted?(email)
extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
end

def self.add_custom_domains(domains)
domains.each do |domain|
BLACKLIST.add(domain)
end
end

def self.extract_all_domain_suffixes(email)
domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase

Expand Down
12 changes: 12 additions & 0 deletions test/platform.ruby.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ def test_extract_all_domain_suffixes
expected = %w(sub.example.org example.org org)
assert_equal expected, MailChecker.extract_all_domain_suffixes('test@sub.example.org')
end

def test_add_custom_domains
valid!('foo@youtube.com')
valid!('foo@google.com')
valid!('ok@gmail.com')

MailChecker.add_custom_domains(['youtube.com', 'google.com'])

invalid!('foo@youtube.com')
invalid!('foo@google.com')
valid!('ok@gmail.com')
end
end

0 comments on commit 167cad2

Please sign in to comment.