Sha256: c103020f8516883ec662c94b29e0042cf47aed5d2b63ccb464d1af0caa88cb7e

Contents?: true

Size: 607 Bytes

Versions: 5

Compression:

Stored size: 607 Bytes

Contents

class Wupee::NotificationType < ActiveRecord::Base
  validates :name, presence: true
  validates :name, uniqueness: true

  has_many :notification_type_configurations, foreign_key: :notification_type_id, dependent: :destroy

  def self.create_configurations_for(*receivers)
    class_eval do
      receivers.each do |receiver|
        after_create do
          receiver.to_s.constantize.pluck(:id).each do |receiver_id|
            Wupee::NotificationTypeConfiguration.create!(notification_type: self, receiver_type: receiver, receiver_id: receiver_id)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wupee-1.0.4 app/models/wupee/notification_type.rb
wupee-1.0.3 app/models/wupee/notification_type.rb
wupee-1.0.2 app/models/wupee/notification_type.rb
wupee-1.0.1 app/models/wupee/notification_type.rb
wupee-1.0.0 app/models/wupee/notification_type.rb