Sha256: 85be6b531cef2bdfeb9323562aaedced4e6ac1e713fda6788f1c0e62143b16b6

Contents?: true

Size: 795 Bytes

Versions: 2

Compression:

Stored size: 795 Bytes

Contents

require 'singleton'
require 'forwardable'

module Rocketman
  class Registry
    include Singleton

    def initialize
      @registry = {}
    end

    def register_event(event)
      if @registry[event]
        return @registry[event]
      else
        @registry[event] = {}
      end
    end

    def register_consumer(event, consumer, action)
      @registry[event][consumer] = action
    end

    def get_events
      @registry.keys
    end

    def get_consumers_for(event)
      @registry[event]
    end

    def event_exists?(event)
      !@registry[event].nil?
    end

    # This is to help hide the Singleton interface from the rest of the code
    class << self
      extend Forwardable
      def_delegators :instance, *Rocketman::Registry.instance_methods(false)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rocketman-0.3.0 lib/rocketman/registry.rb
rocketman-0.2.0 lib/rocketman/registry.rb