Module: Ditty::Services::Email

Extended by:
ActiveSupport::Inflector
Defined in:
lib/ditty/services/email.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config=(value) ⇒ Object

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



14
15
16
# File 'lib/ditty/services/email.rb', line 14

def config=(value)
  @config = value
end

Class Method Details

.config!Object



16
17
18
19
20
21
# File 'lib/ditty/services/email.rb', line 16

def config!
  cfg = config
  Mail.defaults do
    delivery_method cfg[:delivery_method].to_sym, (cfg[:options] || {})
  end
end

.deliver(email, to = nil, options = {}) ⇒ Object



31
32
33
# File 'lib/ditty/services/email.rb', line 31

def deliver(email, to = nil, options = {})
  generate(email, to, options).deliver!
end

.generate(email, to = nil, options = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ditty/services/email.rb', line 23

def generate(email, to = nil, options = {})
  config!
  options[:to] ||= to unless to.nil?
  options[:from] ||= config[:from] unless config[:from].nil?
  email = from_symbol(email, options) if email.is_a? Symbol
  email
end