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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mailpeek/delivery.rb', line 14

def initialize(options = {})
  options[:location] ||= Mailpeek.configuration.location
  options[:limit] ||= Mailpeek.configuration.limit
  options[:limit] = options[:limit].to_i

  if options[:location].nil?
    raise InvalidOption, 'A location option is required when using Mailpeek'
  end

  # rubocop:disable Style/GuardClause
  if options[:limit].nil?
    raise InvalidOption, 'A limit option is required when using Mailpeek'
  elsif options[:limit] <= 0
    raise InvalidOption, 'A limit option is an invalid number'
  end

  # rubocop:enable Style/GuardClause

  self.settings = options
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



12
13
14
# File 'lib/mailpeek/delivery.rb', line 12

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mailpeek/delivery.rb', line 35

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

  clean_up

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

  save_email(mail, basepath)

  return true unless mail.attachments.any?

  add_attachments(mail, basepath)
end