Sha256: 00cfef2c32bec8b6f5c2134a6c14d20368f2839af08e274d30ed4f5d216c5bd7

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'active_support/core_ext/hash'
require "mongo_mapper"

# We are required to choose a database name
MongoMapper.database = "streamit-#{Rails.env}"

module Streamit
  autoload :DSL,   'streamit/dsl'
  autoload :Store, 'streamit/store'
  
  def self.setup
    yield self
  end
  
  # Set which store to use.
  #
  #   Streamit.set_store { Stream }
  #
  def self.set_store(&block)
    singleton_class.send :define_method, :store, &block
  end

  # Place holder for the store.
  def self.store; end
  
  def self.save_stream!(args)
    # insert to queue
    self.queue << args
  end
  
  # Queue related methods
  def self.finish!
    queue << nil
    thread.join
    @thread = nil
    thread
  end
  
  def self.queue
    @queue ||= Queue.new
  end
  
  def self.thread
    @thread ||= Thread.new do
      while args = queue.pop
        store.save_stream!(args)
      end
    end
  end 
  
end

require 'streamit/engine'

require 'active_support/i18n'
I18n.load_path << File.expand_path('../streamit/locales/en.yml', __FILE__)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
streamit-0.0.6.2 lib/streamit.rb
streamit-0.0.6.1 lib/streamit.rb
streamit-0.0.6 lib/streamit.rb