class LetterOpener::DeliveryMethod
Attributes
settings[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/letter_opener/delivery_method.rb, line 10 def initialize(options = {}) options[:message_template] ||= LetterOpener.configuration.message_template options[:location] ||= LetterOpener.configuration.location raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil? self.settings = options end
Public Instance Methods
deliver!(mail)
click to toggle source
# File lib/letter_opener/delivery_method.rb, line 19 def deliver!(mail) validate_mail!(mail) location = File.join(settings[:location], "#{Time.now.to_f.to_s.tr('.', '_')}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}") messages = Message.rendered_messages(mail, location: location, message_template: settings[:message_template]) Launchy.open("file:///#{messages.first.filepath}") end
Private Instance Methods
validate_mail!(mail)
click to toggle source
# File lib/letter_opener/delivery_method.rb, line 29 def validate_mail!(mail) if !mail.smtp_envelope_from || mail.smtp_envelope_from.empty? raise ArgumentError, "SMTP From address may not be blank" end if !mail.smtp_envelope_to || mail.smtp_envelope_to.empty? raise ArgumentError, "SMTP To address may not be blank" end end