Class: Shark::MailingService::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/shark/mailing_service/mailer.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layout:, template_path:, template_name:) ⇒ Mailer

Returns a new instance of Mailer.



43
44
45
46
47
# File 'lib/shark/mailing_service/mailer.rb', line 43

def initialize(layout:, template_path:, template_name:)
  @layout = layout
  @template_name = template_name
  @template_path = template_path
end

Class Attribute Details

.layoutObject



9
10
11
# File 'lib/shark/mailing_service/mailer.rb', line 9

def layout
  @layout || MailingService.config.default_layout
end

.template_rootObject



25
26
27
# File 'lib/shark/mailing_service/mailer.rb', line 25

def template_root
  @template_root || MailingService.config.default_template_root
end

Instance Attribute Details

#layoutObject (readonly)

Returns the value of attribute layout.



41
42
43
# File 'lib/shark/mailing_service/mailer.rb', line 41

def layout
  @layout
end

#template_nameObject (readonly)

Returns the value of attribute template_name.



41
42
43
# File 'lib/shark/mailing_service/mailer.rb', line 41

def template_name
  @template_name
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



41
42
43
# File 'lib/shark/mailing_service/mailer.rb', line 41

def template_path
  @template_path
end

Class Method Details

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



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shark/mailing_service/mailer.rb', line 13

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

  instance = new(
    layout: layout,
    template_name: method.to_s,
    template_path: File.join(template_root.to_s, name.underscore)
  )
  instance.send(method, *args)
  instance
end

Instance Method Details

#deliverObject Also known as: deliver_now



49
50
51
# File 'lib/shark/mailing_service/mailer.rb', line 49

def deliver
  @mail.save
end