Sha256: 3f3ca2e53b848a4f3f292f16ef42fc6bcc75d0f67d3f0708b6a811d218e8a444

Contents?: true

Size: 780 Bytes

Versions: 7

Compression:

Stored size: 780 Bytes

Contents

require 'active_support'

module Chatterbox
  def handle_notice(message)
    publish_notice(message)
    message
  end
  
  alias_method :notify, :handle_notice

  def publish_notice(message)
    Publishers.publishers.each { |p| p.call(message.with_indifferent_access) }
  end
  
  def logger
    @logger ||= Logger.new(nil)
  end
  
  def logger=(logger)
    @logger = logger
  end
  
  def register(&blk)
    Publishers.register(&blk)
  end
  
  extend self
  
  module Publishers
    def publishers
      @publishers ||= []
    end
      
    def register(&blk)
      Chatterbox.logger.debug { "Registering publisher: #{blk}"}
      publishers << blk
      blk
    end
    
    def clear!
      @publishers = []
    end

    extend self
  end
end

require "chatterbox/services"

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
chatterbox-0.6.2 lib/chatterbox.rb
chatterbox-0.6.1 lib/chatterbox.rb
chatterbox-0.6.0 lib/chatterbox.rb
chatterbox-0.5.4 lib/chatterbox.rb
chatterbox-0.5.3 lib/chatterbox.rb
chatterbox-0.5.1 lib/chatterbox.rb
chatterbox-0.5.0 lib/chatterbox.rb