Sha256: 75cb2e843d23073d059bd0e4c53691c37128e69febd2a109a4e20f5547089085

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Rad
  module Processors    
    class LetterBuilder < Processor
      def call                
        # prepare
        controller = workspace.controller.must_be.present
        raise "The controller #{controller} must be a Rad::MailController!" unless controller.is_a? Rad::MailController
        action = workspace.action = workspace.method_name

        # call
        content = catch :halt_render do
          controller.run_callbacks :action, method: action do          
            # call controller
            controller.send action, *workspace.arguments
            # render view
            controller.render action: action          
          end
        end
        
        controller.body = content unless content.blank?
        
        # letter
        workspace.letter = ::Rad::Letter.new(
          from: controller.from,
          to: controller.to,
          subject: controller.subject,
          body: controller.body
        )
        workspace.letter.validate!
        
        next_processor.call if next_processor
      end          
    
    end    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/mail/processors/letter_builder.rb