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.



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

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



25
26
27
28
# File 'lib/ditty/emails/base.rb', line 25

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.



7
8
9
# File 'lib/ditty/emails/base.rb', line 7

def locals
  @locals
end

#mailObject

Returns the value of attribute mail.



7
8
9
# File 'lib/ditty/emails/base.rb', line 7

def mail
  @mail
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/ditty/emails/base.rb', line 7

def options
  @options
end

Class Method Details

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



67
68
69
70
# File 'lib/ditty/emails/base.rb', line 67

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

Instance Method Details

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



15
16
17
18
19
20
21
22
23
# File 'lib/ditty/emails/base.rb', line 15

def deliver!(to = nil, locals = {})
  options[:to] = to unless to.nil?
  @locals.merge!(locals)
  %i[to from subject].each do |param|
    mail.send(param, options[param]) if options[param]
  end
  mail.body content
  mail.deliver!
end

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/ditty/emails/base.rb', line 30

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