Sha256: a8a58f384ea3e9376ef3ee8028e01c8420d7a35b2bd45bc6df92802abf9e8b85

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

class Syncano
  module Packets
    # Class representing notification packets used in communication with the Sync Server
    class Notification < Syncano::Packets::Base
      attr_reader :id, :type, :channel, :source, :target, :data

      # Constructor for Syncano::Packets::Notification object
      # @param [Hash] attributes
      def initialize(attributes)
        super(attributes)
        self.id = attributes[:id]
        self.type = attributes[:type]
        self.channel = attributes[:channel]
        self.source = attributes[:source]
        self.target = attributes[:target]

        if type == 'change'
          self.data = {
            added: attributes[:add],
            updated: attributes[:replace],
            deleted: attributes[:delete]
          }
        else
          self.data = attributes[:data]
        end
      end

      # Returns true if is a notification packet
      # @return [TrueClass, FalseClass]
      def notification?
        true
      end

      private

      attr_writer :id, :type, :channel, :source, :target, :data
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
syncano-3.1.4 lib/syncano/packets/notification.rb
syncano-3.1.3 lib/syncano/packets/notification.rb
syncano-3.1.2 lib/syncano/packets/notification.rb
syncano-3.1.1 lib/syncano/packets/notification.rb
syncano-3.1.1.beta5 lib/syncano/packets/notification.rb
syncano-3.1.1.beta4 lib/syncano/packets/notification.rb
syncano-3.1.1.beta3 lib/syncano/packets/notification.rb
syncano-3.1.1.beta2 lib/syncano/packets/notification.rb
syncano-3.1.1.beta lib/syncano/packets/notification.rb