lib/notifiable/notification.rb in notifiable-rails-0.24.3 vs lib/notifiable/notification.rb in notifiable-rails-0.26.0

- old
+ new

@@ -1,35 +1,20 @@ 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 + serialize :parameters + has_many :notification_statuses, :class_name => 'Notifiable::NotificationStatus', :dependent => :destroy + 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] @@ -37,10 +22,14 @@ notifier = clazz.new(Rails.env, self) self.app.configure(provider, notifier) @notifiers[provider] = notifier end - notifiers[provider].send_notification(d) if d.is_valid? + notifiers[provider].send_notification(d) + end + + def send_params + @send_params ||= (self.parameters ? self.parameters : {}).merge({:n_id => self.id}) end private def notifiers @notifiers ||= {} \ No newline at end of file