Sha256: 93cf924a7bbc0c857d306e401e966700324fb25b0906dbfbbfc2adf1d3a991de

Contents?: true

Size: 1.11 KB

Versions: 24

Compression:

Stored size: 1.11 KB

Contents

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

        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

24 entries across 24 versions & 1 rubygems

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