Sha256: efd111f6e19ac5bcc132b85681132b19ea62c5d1973e81f8db0e62b2be84269b

Contents?: true

Size: 615 Bytes

Versions: 3

Compression:

Stored size: 615 Bytes

Contents

module LetterOpener
  class DeliveryMethod
    class InvalidOption < StandardError; end

    attr_accessor :settings

    def initialize(options = {})
      raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil?
      self.settings = options
    end

    def deliver!(mail)
      location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
      messages = Message.rendered_messages(location, mail)
      Launchy.open("file:///#{URI.parse(URI.escape(messages.first.filepath))}")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
letter_opener-1.3.0 lib/letter_opener/delivery_method.rb
letter_opener-1.2.0 lib/letter_opener/delivery_method.rb
letter_opener-1.1.2 lib/letter_opener/delivery_method.rb