Module: Feste::Mailer::InstanceMethods

Defined in:
lib/feste/mailer.rb

Instance Method Summary collapse

Instance Method Details

#mail(headers = {}, &block) ⇒ Mail?

Returns a Mail object or nil based on if the action has been categorized and if the subscriber is unsubscribed The subscriber is supplied as an argument in the headers through the :subscriber key. The :subscriber key is stripped from the headers before they are given as an argument to the superclass. If no subscriber is provided, then one will be inferred from the :to header.

unsubscribed

Parameters:

  • (Hash, &block)

Returns:

  • (Mail, nil)

    , the Mail object or nil if the subscriber is



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/feste/mailer.rb', line 25

def mail(headers = {}, &block)
  if current_action_category.present?
    return message if @_mail_was_called && headers.blank? && !block

    email = headers[:to].is_a?(String) ? headers[:to] : headers[:to].first
    subscriber = headers[:subscriber] ||
      Feste::Subscription.find_subscribed_user(email)
    headers = headers.except(:subscriber)

    if recipient_subscribed?(subscriber)
      generate_subscription_token!(subscriber)
      message = super(headers, &block)
    else
      nil
    end          
  else
    super(headers, &block)
  end
end