Sha256: d53bf1427f530d7077026b8e2576b64f088a709c54684e598156ccae3bd6c669

Contents?: true

Size: 933 Bytes

Versions: 9

Compression:

Stored size: 933 Bytes

Contents

require File.join(File.dirname(__FILE__), *%w[chatterbox notification])
require File.join(File.dirname(__FILE__), *%w[consumers])

module Chatterbox

  def handle_notice(message)
    notice = Notification.new(message).notice
    publish_notice(notice)
  end

  def publish_notice(notice)
    Publishers.publishers.each { |p| p.call(notice) }
  end
  
  def logger
    @logger ||= rails_default_logger || Logger.new(STDOUT)
  end
  
  def logger=(logger)
    @logger = logger
  end
  
  def rails_default_logger
    defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
  end
  
  extend self
  
  module Publishers

    class << self

      def publishers
        @publishers ||= []
      end
      
      def register(&blk)
        Chatterbox.logger.debug { "Registering publisher: #{blk}"}
        publishers << blk
        blk
      end
      
      def clear!
        @publishers = []
      end

    end
    
  end
  
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
relevance-chatterbox-0.1.0 lib/chatterbox.rb
relevance-chatterbox-0.2.0 lib/chatterbox.rb
relevance-chatterbox-0.2.1 lib/chatterbox.rb
relevance-chatterbox-0.2.2 lib/chatterbox.rb
relevance-chatterbox-0.3.0 lib/chatterbox.rb
relevance-chatterbox-0.3.1 lib/chatterbox.rb
relevance-chatterbox-0.3.2 lib/chatterbox.rb
relevance-chatterbox-0.3.3 lib/chatterbox.rb
chatterbox-0.3.3 lib/chatterbox.rb