Class: LetterOpener::DeliveryMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/letter_opener/delivery_method.rb

Defined Under Namespace

Classes: InvalidOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DeliveryMethod

Returns a new instance of DeliveryMethod.

Raises:



10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



8
9
10
# File 'lib/letter_opener/delivery_method.rb', line 8

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



19
20
21
22
23
24
25
# 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