Sha256: db2f967288d4da9378fe40a64672e29fb43f3d62b46ac043aaf415bad9267ce9

Contents?: true

Size: 742 Bytes

Versions: 6

Compression:

Stored size: 742 Bytes

Contents

module Faye
  module Publisher
    
    def count_subscribers(event_type)
      return 0 unless @subscribers and @subscribers[event_type]
      @subscribers[event_type].size
    end
    
    def add_subscriber(event_type, listener)
      @subscribers ||= {}
      list = @subscribers[event_type] ||= []
      list << listener
    end
    
    def remove_subscriber(event_type, listener)
      return unless @subscribers and @subscribers[event_type]
      @subscribers[event_type].delete_if(&listener.method(:==))
    end
    
    def publish_event(event_type, *args)
      return unless @subscribers and @subscribers[event_type]
      @subscribers[event_type].each do |listener|
        listener.call(*args)
      end
    end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faye-0.5.5 lib/faye/mixins/publisher.rb
faye-0.5.4 lib/faye/mixins/publisher.rb
faye-0.5.3 lib/faye/mixins/publisher.rb
faye-0.5.2 lib/faye/mixins/publisher.rb
faye-0.5.1 lib/faye/mixins/publisher.rb
faye-0.5.0 lib/faye/mixins/publisher.rb