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

Version Path
renalware-core-2.0.8 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.7 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.5 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.4 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.3 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.2 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.1 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/letters/approve_letter.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/letters/approve_letter.rb