Class: Mailpeek::Delivery

Inherits:
Object
  • Object
show all
Includes:
Mail::CheckDeliveryParams
Defined in:
lib/mailpeek/delivery.rb

Overview

Public: Delivery

Defined Under Namespace

Classes: InvalidOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Delivery

Returns a new instance of Delivery.



12
13
14
15
16
17
18
19
# File 'lib/mailpeek/delivery.rb', line 12

def initialize(options = {})
  if options[:location].nil?
    raise(
      InvalidOption,
      'A location option is required when using Mailpeek')
  end
  self.settings = options
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



10
11
12
# File 'lib/mailpeek/delivery.rb', line 10

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mailpeek/delivery.rb', line 21

def deliver!(mail)
  check_delivery_params(mail) if respond_to?(:check_delivery_params)

  FileUtils.mkdir_p(settings[:location])

  filepath = File.join(settings[:location], Time.now.to_i.to_s)

  File.open(filepath, 'w') do |f|
    f.write mail.to_s
  end
end