Module: AhoyEmail::Mailer

Extended by:
ActiveSupport::Concern
Defined in:
lib/ahoy_email/mailer.rb

Instance Method Summary collapse

Instance Method Details

#ahoy_optionsObject



42
43
44
# File 'lib/ahoy_email/mailer.rb', line 42

def ahoy_options
  @ahoy_options ||= AhoyEmail.default_options
end

#call_ahoy_options(options, key) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ahoy_email/mailer.rb', line 59

def call_ahoy_options(options, key)
  v = ahoy_options[key]
  options[key] = v.respond_to?(:call) ? instance_exec(&v) : v

  # only call other options if needed
  if options[key]
    AhoyEmail::Utils::OPTION_KEYS[key].each do |k|
      v = ahoy_options[k]
      options[k] = v.respond_to?(:call) ? instance_exec(&v) : v
    end
  end
end

#save_ahoy_optionsObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ahoy_email/mailer.rb', line 46

def save_ahoy_options
  Safely.safely do
    options = {}
    call_ahoy_options(options, :message)
    call_ahoy_options(options, :utm_params)
    call_ahoy_options(options, :click)

    if options[:message] || options[:utm_params] || options[:click]
      AhoyEmail::Processor.new(self, options).perform
    end
  end
end