Sha256: 6e478530e4455408d9dd45f527090f6b495cc148973c3f2d480e07415234394e

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

module Notifiable

	class NotifierBase
    
    attr_accessor :env
    
		def send_notification(notification, device_token)
      # todo - add before hook
      enqueue(notification, device_token)
      # todo - add after hook       				
    end
    
    def close
      flush
      save_receipts
    end
    
    protected    
    def flush
      
    end
    
    def processed(notification, device_token)
      receipts << {:notification_id => notification.id, :device_token_id => device_token.id }
      
      if receipts.count > 10000
        save_receipts
      end
    end
    
    def test_env?
      self.env == "test"
    end
    
    private
    def receipts
      @receipts ||= []
    end
    
    def save_receipts
      Notifiable::NotificationDeviceToken.bulk_insert! receipts
      @receipts = []
    end
	end


end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
notifiable-rails-0.5.1 lib/notifiable/notifier_base.rb
notifiable-rails-0.5.0 lib/notifiable/notifier_base.rb
notifiable-rails-0.4.0 lib/notifiable/notifier_base.rb