Sha256: 1005a973dc50733a7ee4b9bd497892929d9a377576b6e29022a9245a35fa6f2d
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
module Notifiable class Notification < ActiveRecord::Base serialize :params has_many :localized_notifications, :class_name => 'Notifiable::LocalizedNotification', :dependent => :destroy accepts_nested_attributes_for :localized_notifications, reject_if: proc { |attributes| attributes['message'].blank? } belongs_to :app, :class_name => 'Notifiable::App' validates :app, presence: true def notification_statuses Notifiable::NotificationStatus.joins(:localized_notification).where('notifiable_localized_notifications.notification_id' => self.id) end def batch yield(self) close end def localized_notification(locale) self.localized_notifications.find_by(:locale => locale) end def add_notifiable(notifiable) notifiable.device_tokens.each do |d| self.add_device_token(d) end end def add_device_token(d) provider = d.provider.to_sym unless notifiers[provider] clazz = Notifiable.notifier_classes[provider] raise "Notifier #{provider} not configured" unless clazz notifier = clazz.new(Rails.env, self) self.app.configure(provider, notifier) @notifiers[provider] = notifier end notifiers[provider].send_notification(d) if d.is_valid? end private def notifiers @notifiers ||= {} end def close notifiers.each_value {|n| n.close} @notifiers = nil summarise end def summarise self.sent_count = self.notification_statuses.count self.gateway_accepted_count = self.notification_statuses.where(:status => 0).count self.save end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
notifiable-rails-0.21.1 | lib/notifiable/notification.rb |