Class: Nuntius::MailAllowList

Inherits:
Object
  • Object
show all
Defined in:
lib/nuntius/mail_allow_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(allow_list = []) ⇒ MailAllowList

Returns a new instance of MailAllowList.



7
8
9
10
# File 'lib/nuntius/mail_allow_list.rb', line 7

def initialize(allow_list = [])
  allow_list = [] if allow_list.blank?
  @allow_list = allow_list.map(&:downcase)
end

Instance Method Details

#allowed?(email) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/nuntius/mail_allow_list.rb', line 12

def allowed?(email)
  return true if @allow_list.blank?

  mail_to = Mail::Address.new(email.downcase)
  allow_list_match = @allow_list.detect do |allow|
    allow == (allow.include?('@') ? mail_to.to_s : mail_to.domain)
  end

  allow_list_match.present?
end