Sha256: 41e3665d00c4dc745fe81dd04c7f6ee742abef9a0c235698bd25d79c47dda39e

Contents?: true

Size: 1.42 KB

Versions: 99

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/messaging"

# Builds a new MessageForm form object. MessageForm is used behind the html form when displaying a
# `Send Message` Dialog the first time. Note that we don't use this builder again on e.g.
# form submission - at that point all the required params are in the form payload - this is
# only for the initial MesageForm creation.
#
module Renalware
  module Messaging
    module Internal
      class MessageFormBuilder
        attr_reader :patient, :params

        def initialize(patient:, params:)
          @patient = patient
          @params = params
        end

        def call
          MessageForm.new(
            subject: build_subject,
            recipient_ids: build_recipient_ids,
            replying_to_message_id: replying_to_message_id
          )
        end

        private

        def build_subject
          replying? ? "Re: #{replying_to_message.subject}" : patient.to_s
        end

        def build_recipient_ids
          replying? ? Array(replying_to_message.author_id) : []
        end

        def replying_to_message
          return NullObject.instance unless replying?

          @replying_to_message ||= Message.find(replying_to_message_id)
        end

        def replying_to_message_id
          params[:replying_to_message_id]
        end

        def replying?
          replying_to_message_id.present?
        end
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
renalware-core-2.0.132 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.131 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.130 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.129 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.128 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.127 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.126 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.125 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.124 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.123 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.121 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.120 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.119 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.118 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.117 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.116 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.115 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.113 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.112 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.111 app/models/renalware/messaging/internal/message_form_builder.rb