Class: LetterBuilder

Inherits:
Rad::Conveyors::Processor show all
Defined in:
lib/rad/mailer/processors/letter_builder.rb

Instance Attribute Summary

Attributes inherited from Rad::Conveyors::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Rad::Conveyors::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Rad::Conveyors::Processor

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rad/mailer/processors/letter_builder.rb', line 4

def call
  # prepare
  controller = workspace.controller.must_be.present
  raise "The controller #{controller} must be a Rad::Mailer::MailerController!" unless controller.is_a? Rad::Mailer::MailerController
  action_name = workspace.action_name = workspace.method_name

  # call
  controller.set! params: workspace.params, action_name: workspace.action_name
  content = controller.call action_name, *workspace.arguments

  controller.body = content unless content.blank?

  # letter
  workspace.letter = ::Rad::Mailer::Letter.new(
    from: controller.from,
    to: controller.to,
    subject: controller.subject,
    body: controller.body
  )
  workspace.letter.validate!

  next_processor.call if next_processor
end