Sha256: 794ee370bb7b78bcc46f570031bc63df1712ad962a58d226c328953901f117da

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

require "renalware/letters"
require "attr_extras"

module Renalware
  module Letters
    module Delivery
      # Utility class to help us resolve the correct email address when sending to the practice.
      # If we allow_external_mail then we use the practice email, other wise we use the email
      # of the last user to update the letter (useful for testing, ie you get the GP email if you
      # approve the letter) or a system default for testing if the user has no email address.
      class PracticeEmail
        pattr_initialize :letter
        delegate :patient, to: :letter
        delegate :practice, to: :patient
        delegate :config, to: :Renalware

        def address
          if config.allow_external_mail
            practice&.email # nil is acceptable
          else
            user_email = letter.updated_by&.email
            user_email.presence || config.fallback_email_address_for_test_messages
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc7 app/models/renalware/letters/delivery/practice_email.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/letters/delivery/practice_email.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/letters/delivery/practice_email.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/letters/delivery/practice_email.rb