Class: Ditty::Emails::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ditty/emails/base.rb

Direct Known Subclasses

ForgotPassword

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/ditty/emails/base.rb', line 11

def initialize(options = {})
  @mail = options[:mail] || Mail.new
  @locals = options[:locals] || {}
  @options = base_options.merge options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
# File 'lib/ditty/emails/base.rb', line 33

def method_missing(method, *args, &block)
  return super unless respond_to_missing?(method)

  mail.send(method, *args, &block)
end

Instance Attribute Details

#localsObject

Returns the value of attribute locals.



9
10
11
# File 'lib/ditty/emails/base.rb', line 9

def locals
  @locals
end

#mailObject

Returns the value of attribute mail.



9
10
11
# File 'lib/ditty/emails/base.rb', line 9

def mail
  @mail
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/ditty/emails/base.rb', line 9

def options
  @options
end

Class Method Details

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



79
80
81
82
# File 'lib/ditty/emails/base.rb', line 79

def deliver!(to = nil, options = {})
  locals = options[:locals] || {}
  new(options).deliver!(to, locals)
end

Instance Method Details

#deliver!(to = nil, locals = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ditty/emails/base.rb', line 17

def deliver!(to = nil, locals = {})
  options[:to] = to unless to.nil?
  @locals.merge!(locals)
  i[to from subject content_type].each do |param|
    next unless options[param]

    @locals[param] ||= options[param]
    mail.send(param, options[param])
  end
  html = content
  mail.html_part do
    body html
  end
  mail.deliver!
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ditty/emails/base.rb', line 39

def respond_to_missing?(method, _include_private = false)
  mail.respond_to? method
end