Sha256: c0fee1d8550e2250fa5f02f5103694ffe93227154f6492ba80089de1c121e2b2
Contents?: true
Size: 1.01 KB
Versions: 17
Compression:
Stored size: 1.01 KB
Contents
require_dependency "renalware/letters" require "attr_extras" module Renalware module Letters class ApproveLetter include Broadcasting pattr_initialize :letter class << self alias_method :build, :new end def call(by:) Letter.transaction do sign(by: by) archive_content(by: by) archive_recipients broadcast(:letter_approved, letter) end end private def sign(by:) # Needs to be saved before changing the STI type (signature would be lost otherwise) letter.sign(by: by).save! end # Note that generate_archive returns the letter as a Letter::Approved object. # We need to update our letter reference as it's this Approved letter we need to broadcast # to subscribers. def archive_content(by:) @letter = letter.generate_archive(by: by) letter.save! end def archive_recipients letter.archive_recipients! end end end end
Version data entries
17 entries across 17 versions & 1 rubygems