Class: LetterOpener::DeliveryMethod
- Inherits:
-
Object
- Object
- LetterOpener::DeliveryMethod
- Defined in:
- lib/letter_opener/delivery_method.rb
Defined Under Namespace
Classes: InvalidOption
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(options = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(options = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
10 11 12 13 14 15 16 17 18 |
# File 'lib/letter_opener/delivery_method.rb', line 10 def initialize( = {}) [:message_template] ||= LetterOpener.configuration. [:location] ||= LetterOpener.configuration.location [:file_uri_scheme] ||= LetterOpener.configuration.file_uri_scheme raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if [:location].nil? self.settings = end |
Instance Attribute Details
#settings ⇒ Object
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
20 21 22 23 24 25 26 |
# File 'lib/letter_opener/delivery_method.rb', line 20 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]}") = Message.(mail, location: location, message_template: settings[:message_template]) ::Launchy.open("#{settings[:file_uri_scheme]}#{.first.filepath}") end |