Sha256: 3662d32e458268fe0aec3ce52e1876bdaf7a9caa86637c2cbb2304f9ec6f251f

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

module Space
  module Events
    autoload :Subscription, 'space/events/subscription'
    autoload :Sources,      'space/events/sources'

    class << self
      def sources
        @sources ||= Sources.new(self)
      end

      def subscriptions
        @subscriptions ||= []
      end

      def events
        @events ||= []
      end

      def subscribe(observer, *types)
        subscriptions << Subscription.new(observer, types)
      end

      def flush
        event = events.first
        events.clear
        notify(event, false) if event
      end

      def notify(event)
        # log event
        subscriptions.each do |subscription|
          subscription.notify(event)
        end
      end
    end

    def notify(*args)
      Events.notify(*args)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
space-0.0.6 lib/space/events.rb