Sha256: 86639df3355f5ad90251576ba3c48c82b302bba80afe3990c80d83973f497355

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

module Ddr
  module Alerts
    class Message < ActiveRecord::Base

      has_many :contexts, class_name: "Ddr::Alerts::MessageContext", inverse_of: :message, dependent: :destroy

      scope :active, -> { where(active: true) }

      scope :ddr, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_DDR }) }
      scope :repository, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_REPOSITORY }) }

      def to_s
        actv = active ? 'ACTIVE' : 'INACTIVE'
        ctxs = contexts.map { |context| context.context }
        "[#{id}] [#{ctxs.join(';')}] [#{actv}] [\"#{message}\"]"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddr-alerts-0.3.0 lib/ddr/alerts/message.rb