Sha256: bfa8d25f9b15d79d5d3c18b18d14c9c0ae8e776ae98ab43cffb6dd9dcbbcf585

Contents?: true

Size: 694 Bytes

Versions: 5

Compression:

Stored size: 694 Bytes

Contents

module Massive
  module Notifiers
    class Base
      include Massive::Locking

      attr_accessor :id, :last, :options

      def initialize(id, options={})
        self.id   = id
        self.last = {}

        self.options = options || {}
      end

      def notify(message, data=nil, &block)
        send_notification(message, data, &block) unless locked?(message, expiration)
      end

      protected

      def send_notification(message, data, &block)
        data = block.call if block_given?

        self.last = { message: message, data: data }
      end

      def expiration
        options[:expiration] || 1000  # 1 second between each notification
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
massive-0.4.0 lib/massive/notifiers/base.rb
massive-0.3.0 lib/massive/notifiers/base.rb
massive-0.2.0 lib/massive/notifiers/base.rb
massive-0.1.1 lib/massive/notifiers/base.rb
massive-0.1.0 lib/massive/notifiers/base.rb