Sha256: 5c4e3246a3aac5a2610774c70e7deaf10ed243ab0b4cf5f85c91ef7cce19b1aa

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

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

24 entries across 24 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.7 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.5 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.4 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.3 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.2 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.1 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/messaging/internal/message_form_builder.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/messaging/internal/message_form_builder.rb