Sha256: 6bbd69bd7514447ffe644c34c5992ef5b23b1d1602aea3ab4a21f32519bb86bb

Contents?: true

Size: 854 Bytes

Versions: 1

Compression:

Stored size: 854 Bytes

Contents

module PubsubNotifier
  module Proxy
    def self.included(klass)
      klass.extend ClassMethods
    end

    module ClassMethods
      def subscribe(subscriber_name, options = {})
        subscriber  = subscriber_name.to_s.constantize
        broadcaster = (options.delete(:async) ? broadcasters[:async] : nil) || broadcasters[:default]
        broadcaster.configure(options) if broadcaster.respond_to?(:configure)
        pubsub.subscribe(subscriber, broadcaster: broadcaster)
      end

      def pubsub
        @_pubsub ||= ::PubsubNotifier::Pubsub.new
      end

      private

        def broadcasters
          Wisper.configuration.broadcasters
        end
    end

    def broadcast(event)
      pubsub.call(event, self)
    end

    alias_method :publish, :broadcast

    private

      def pubsub
        self.class.pubsub
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pubsub_notifier-0.1.2 lib/pubsub_notifier/proxy.rb