Class: ActiveWrapper::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/active_wrapper/mail.rb

Defined Under Namespace

Classes: Mailer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Mail

Returns a new instance of Mail.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_wrapper/mail.rb', line 6

def initialize(options)
  @base = options[:base]
  @config = {
    :smtp => options[:smtp] || {},
    :sendmail => options[:sendmail] || nil,
    :imap => options[:imap] || {}
  }
  @env = options[:env].to_s
  
  path = "#{base}/config/mail.yml"
  
  if File.exists?(path)
    yaml = YAML::load(File.open(path))
    if yaml && yaml[@env]
      yaml = yaml[@env].to_options
      @config[:imap] = yaml[:imap].to_options if yaml[:imap]
      @config[:sendmail] = yaml[:sendmail] if !yaml[:sendmail].nil?
      @config[:smtp] = yaml[:smtp].to_options if yaml[:smtp]
    end
  end
  if @env == 'test'
    ActionMailer::Base.delivery_method = :test
  elsif @config[:sendmail]
    ActionMailer::Base.delivery_method = :sendmail
  elsif @config[:smtp]
    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = @config[:smtp]
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



4
5
6
# File 'lib/active_wrapper/mail.rb', line 4

def base
  @base
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/active_wrapper/mail.rb', line 4

def config
  @config
end

#envObject (readonly)

Returns the value of attribute env.



4
5
6
# File 'lib/active_wrapper/mail.rb', line 4

def env
  @env
end

Instance Method Details

#deliver(options) ⇒ Object



36
37
38
# File 'lib/active_wrapper/mail.rb', line 36

def deliver(options)
  Mailer.deliver_email(options)
end