Sha256: 92b143280224043bf08f58ae1beb09b9fe20b713ee2a58031871f3727bab22a2

Contents?: true

Size: 881 Bytes

Versions: 2

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

module Koine
  module EventManager
    class EventManager
      def initialize
        @internal_listener = EventListener.new
      end

      def listen_to(event, &block)
        @internal_listener.listen_to(event, &block)
      end

      def subscribe(subscriber, to:)
        @internal_listener.subscribe(subscriber, to: to)
      end

      def unsubscribe(subscriber, from:)
        @internal_listener.unsubscribe(subscriber, from: from)
      end

      def attach_listener(listener)
        listeners << listener
      end

      def detach_listener(listener)
        listeners.delete(listener)
      end

      def trigger(event)
        @internal_listener.trigger(event)

        listeners.each do |listener|
          listener.trigger(event)
        end
      end

      def listeners
        @listeners ||= []
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
koine-event_manager-2.1.1 lib/koine/event_manager/event_manager.rb
koine-event_manager-2.1 lib/koine/event_manager/event_manager.rb