Sha256: 157b6ad9e899fa0ca4bb51135a8d91d0a682c7b4a427e80dabea4a0de74f7d13

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/messaging"

# A form object used behind the html messages#new form, and serving to helps us capture
# attributes for a Message and its Recipients. The MessageForm is passed to the SendMessage
# object where it is persisted as a Message with many Recipients through Receipts.
module Renalware
  module Messaging
    module Internal
      class MessageForm
        include ActiveModel::Model
        include Virtus::Model

        attribute :body, String
        attribute :subject, String
        attribute :urgent, Boolean, default: false
        attribute :recipient_ids, Array, default: []
        attribute :replying_to_message_id
        attribute :public, Boolean, default: true

        validates :body, presence: true
        validates :subject, presence: true
        validates :recipient_ids, presence: true, length: { minimum: 1 }

        def initialize(attributes = {})
          remove_blank_recipient_ids_from(attributes)
          super
        end

        private

        def remove_blank_recipient_ids_from(params)
          params[:recipient_ids].reject!(&:blank?) if params.key?(:recipient_ids)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.1.0 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.167 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.166 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.165 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.164 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.163 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.162 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.161 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.160 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.159 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.158 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.157 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.156 app/models/renalware/messaging/internal/message_form.rb
renalware-core-2.0.155 app/models/renalware/messaging/internal/message_form.rb