Skip to content

Commit

Permalink
Merge pull request #185 from Kulgar/master
Browse files Browse the repository at this point in the history
Allow configuration of the 'file///' part in Launchy.open path
  • Loading branch information
nashby authored Dec 6, 2021
2 parents 94a0462 + 5f5ebd6 commit d46a375
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/letter_opener/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module LetterOpener
class Configuration
attr_accessor :location, :message_template
attr_accessor :location, :message_template, :files_storage

def initialize
@location = Rails.root.join('tmp', 'letter_opener') if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
@message_template = 'default'
@files_storage = 'file:///'
end
end
end
3 changes: 2 additions & 1 deletion lib/letter_opener/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class InvalidOption < StandardError; end
def initialize(options = {})
options[:message_template] ||= LetterOpener.configuration.message_template
options[:location] ||= LetterOpener.configuration.location
options[:files_storage] ||= LetterOpener.configuration.files_storage

raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil?

Expand All @@ -21,7 +22,7 @@ def deliver!(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}")
Launchy.open("#{settings[:files_storage]}#{messages.first.filepath}")
end

private
Expand Down

0 comments on commit d46a375

Please sign in to comment.