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
# File 'lib/active_wrapper/mail.rb', line 6

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



34
35
36
# File 'lib/active_wrapper/mail.rb', line 34

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